package com.hongxun.modules.csg.entity.dxf;//-----------------------------------------------------------------------------
// Copyright (c) 2004 Soft Gold Software Corporation.  All Rights Reserved.
//-----------------------------------------------------------------------------

import java.awt.*;
import java.awt.event.*;
import javax.annotation.PostConstruct;
import javax.swing.*;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.*;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.alibaba.fastjson.JSON;
import com.hongxun.modules.bss.entity.DCrossCostEntity;
import com.hongxun.modules.bss.entity.DDrawLineEntity;
import com.hongxun.modules.bss.entity.DPointEntity;
import com.hongxun.modules.csg.entity.CPBaseEntity;
//import com.sun.org.apache.xpath.internal.operations.Bool;
import dxfExporter.*;
import org.springframework.beans.factory.annotation.Value;

/**
 *  导出DXF文件
 *
 *  Frame class for testing a export to DXF.
 */
public class FrmDXFExporter extends JFrame {
  private String DXFEROTT;
  private static DXFExport Xprt;  //实体类（cad版本，线，圆，文字等）
  private String sgStr;
  private static final String AppName = new String("DXFExporter version demo");
  private static final String FilePath = new String("D:\\budgetDXF\\foundation\\2018-dxfExporter.dxf");      //  保存文件名（路径）
  private static final String NewFilePath = new String("C:\\budgetDXF\\foundation\\2018-dxfExporter.dxf");      //  保存文件名（路径）
  private static final String strPixel = "Pixel";                       //  像素
  private static final String strLine = "Line";                         //  线段
  private static final String strPolyline = "Polyline";                 //  折线
  private static final String strRectangle = "Rectangle";               //  矩形框
  private static final String strCircle = "Circle (+small hatch)";      //  圆
  private static final String strEllipse = "Ellipse (+small hatch)";    //  椭圆
  private static final String strArc = "Arc";                           //  圆弧
  private static final String strPolygon = "Polygon (hatch)";           //  五角星
  private static final String strBezier = "Bezier";                     //  曲线
  private static final String str3DFace = "3DFace";                     //  多边形
  private static final String strAll = "All figures";                   //  数字/轮廓
  private static final String strSaveToDXFFile = "Save to DXF file";    //  保存
  private static final String strRedraw = "Redraw";                     //  重绘
  private static final Color sgTextColor = new Color(10, 155, 150);
  private static final Integer tzMinWidth = 1000;                          //  空间宽度
  private static final Integer tzMinHeight = 1000;                         //  空间高度
  private static final Integer bzRectWidth = 340;                       //  图表标识矩形框宽度
  private static final Integer bzRectHeight = 555;                      //  图表标识矩形框高度
  private static final String corporateName = "单位名称";
  private String projectName = "";
  private static final String entryName = "项目名称";
  private static final Integer wuchaData=50;                            //矩形框误差值
  private static final Integer RectWidth=340;                           //标准矩形框的宽度
  private static final Integer zoomNum=200000;                          //经纬度放大倍数
//  private static final String bianYaQiName = "变压器";




  /**
   *  JPanel 是 Java图形用户界面(GUI)工具包swing中的面板容器类，
   *   包含在javax.swing 包中，可以进行嵌套，功能是对窗体中具有相同逻辑功能的组件进行组合
   */
  private JPanel contentPane;           //  内容窗格
  private JPanel jpnlTools;             //  面板容器工具
  private JPanel jpnlDraw;              //  面板重绘

  /**
   *  Graphics类提供基本的几何图形绘制方法，主要有：画线段、画矩形、画圆、画带颜色的图形、画椭圆、画圆弧、画多边形等
   */
  private Graphics grphCanvas;

  /**
   * BorderLayout边界布局管理器把容器的的布局分为五个位置：CENTER、EAST、WEST、NORTH、SOUTH。
   * 依次对应为：上北（NORTH）、下南（SOUTH）、左西（WEST）、右东（EAST），中（CENTER）
   */
  private BorderLayout brdrLayout = new BorderLayout();

  /**
   *  JButton用来创建没有复选框的按钮
   */
  private JButton jbtnSave = new JButton();

  /**
   *  JComboBox下拉框
   */
  private JComboBox jcbFigures = new JComboBox();

  /**
   *  复选框
   */
  Checkbox cbACAD2000 = new Checkbox();

  /*private class DemoDialog extends Dialog implements ActionListener {
    DemoDialog(Frame parent, String title, boolean modal) {
      super(parent, title, modal);
      setLayout(new FlowLayout());
      setSize(300, 200);
      Button btn;
      add(btn = new Button("Ok"));
      btn.addActionListener(this);
    }
    public void actionPerformed(ActionEvent ae) {
      dispose();
    }
  }*/

  //Construct the frame--构建框架
//  public FrmDXFExporter(Map<String , Object> map){
  public FrmDXFExporter(List list , String sv){
    System.err.println("sv==="+sv);
    DXFEROTT = sv;
    projectName = list.get(3).toString();
    //组码--用于选择窗口事件的事件掩码
//    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
      jbInit();//初始化组件
    }
    catch(Exception e) {
      e.printStackTrace();
    }
    /*try {
//      jbtnSave_actionPerformed(map);
      jbtnSave_actionPerformed(list);
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    }*/

  }

  //Component initialization-- 组件初始化
  private void jbInit() throws Exception  {
    Xprt = null;
//    jpnlTools = new JPanel();
    jpnlDraw = new JPanel();
    grphCanvas = jpnlDraw.getGraphics();
    this.setResizable(false); //  设置该帧是否可由用户调整大小。
    this.setTitle(AppName);   //  将该框架的标题设置为指定的字符串。
    //setIconImage(Toolkit.getDefaultToolkit().createImage(FrmDXFExporter.class.getResource("[Your Icon]")));
    contentPane = (JPanel) this.getContentPane(); //  返回内容窗格——包含组件的容器
//    jpnlTools.setLayout(new BorderLayout());      //  设置此容器的布局管理器。

    //动作监听器(复选框)
    jbtnSave.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
//        jbtnSave_actionPerformed(e);
//        jbtnSave_actionPerformed();
      }
    });

    //动作监听器(下拉框)
    jcbFigures.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jcbFigures_actionPerformed(e);
      }
    });

    //设置此组件的边界
//    jpnlDraw.setBorder(BorderFactory.createLoweredBevelBorder());
//    cbACAD2000.setActionCommand("jcbACAD2000");

    cbACAD2000.setLabel("AutoCAD 2000");           // 将此复选框的标签设置为字符串参数

    //添加复选框和下拉框
//    jpnlTools.add(jbtnSave, BorderLayout.EAST);
//    jpnlTools.add(jcbFigures, BorderLayout.WEST);
//    jpnlTools.add(cbACAD2000, BorderLayout.CENTER);

    //下拉框添加选项
//    jcbFigures.addItem(strPixel);
//    jcbFigures.addItem(strLine);
//    jcbFigures.addItem(strPolyline);
//    jcbFigures.addItem(strRectangle);
//    jcbFigures.addItem(strCircle);
//    jcbFigures.addItem(strEllipse);
//    jcbFigures.addItem(strArc);
//    jcbFigures.addItem(strPolygon);
//    jcbFigures.addItem(strBezier);
//    jcbFigures.addItem(str3DFace);
//    jcbFigures.addItem(strAll);


//    contentPane.setLayout(brdrLayout);                  //  设置内容窗格容器的布局管理器

    //  将下拉框和复选框放入到窗格中
//    contentPane.add(jpnlDraw, BorderLayout.CENTER);
//    contentPane.add(jpnlTools, BorderLayout.SOUTH);

    //设置窗口大小
//    setSize(new Dimension(520, 330));

    //  按钮中添加文字(value)
//    jbtnSave.setText(strSaveToDXFFile);

    //  选择所有
//    jcbFigures.setSelectedItem(strAll);

    //返回当前选定的项
    sgStr = (String) jcbFigures.getSelectedItem();
  }


  //  重写，以便在窗口关闭时退出
  // Overridden so we can exit when window is closed
  //
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }
  void jcbFigures_actionPerformed(ActionEvent e) {
    super.processEvent(e);
    sgStr = (String) jcbFigures.getSelectedItem();
    this.repaint();
  }


  /*void jbtnSave_actionPerformed(ActionEvent e) {
    //  处理此窗口上的事件
    super.processEvent(e);

    //
    if (jbtnSave.getText().compareTo(strSaveToDXFFile) == 0 ) {
      Xprt = new DXFExport();
      if (cbACAD2000.getState())
        Xprt.AutoCADVer = Constants.DXFVERSION_R2000;
      Graphics prevDraw = grphCanvas;
      grphCanvas = null;
      DrawFigures();
      grphCanvas = prevDraw;
      try {
        Xprt.saveToFile(FilePath);
        sgStr = "DXF file \"" + FilePath + "\" successfully created...";
      }
      catch(Exception excpt) {
        sgStr = "ERROR: '"+excpt.getMessage()+"'. Cannot save to file...";
      }
      finally {
        Xprt.finalize();
        Xprt = null;
        jbtnSave.setText(strRedraw);
        jcbFigures.setEnabled(false);
        this.repaint();
      }
    }
    else {
      jbtnSave.setText(strSaveToDXFFile);
      jcbFigures.setEnabled(true);
      sgStr = (String) jcbFigures.getSelectedItem();
      this.repaint();
    }
  }*/


//  public void jbtnSave_actionPerformed(Map<String , Object> map) throws UnsupportedEncodingException {
  public void jbtnSave_actionPerformed(List list) throws Exception {
    //  处理此窗口上的事件
//    super.processEvent(e);

    //
//    if (jbtnSave.getText().compareTo(strSaveToDXFFile) == 0 ) {
      Xprt = new DXFExport();
      if (cbACAD2000.getState())
        Xprt.AutoCADVer = Constants.DXFVERSION_R2000;
      Graphics prevDraw = grphCanvas;
      grphCanvas = null;
//      DrawFigures(map);
      DrawFigures(list);  //  画图
      grphCanvas = prevDraw;
      try {
//        Xprt.saveToFile();
//        File file = new File(FilePath);

        String newPath = DXFEROTT+"foundation";

        File dir = new File(newPath);
        if (!dir.exists()) {
          dir.mkdirs();		// 	mkdirs创建多级目录
        }
        //	创建文件
        File checkFile = new File(newPath + "/"+projectName+".dxf");
        if (!checkFile.exists()) {
          checkFile.createNewFile();// 创建目标文件
        }
        String pathOne = newPath + "/"+projectName+".dxf";
        Xprt.saveToFile(pathOne);
        sgStr = "DXF file \"" + pathOne + "\" successfully created...";
//        sgStr = "DXF file \"" + DXFEROTT+"foundation/2018-dxfExporter.dxf" + "\" successfully created...";
      }
      catch(Exception excpt) {
        sgStr = "ERROR: '"+excpt.getMessage()+"'. Cannot save to file...";
      }
      finally {
        Xprt.finalize();
        Xprt = null;
//        jbtnSave.setText(strRedraw);
//        jcbFigures.setEnabled(false);
//        this.repaint();
      }
//    }
//    else {
//      jbtnSave.setText(strSaveToDXFFile);
//      jcbFigures.setEnabled(true);
//      sgStr = (String) jcbFigures.getSelectedItem();
//      this.repaint();
//    }
  }

  /**
   *  涂上容器
   * Paint Handler.
  */
  public void paint(Graphics g)
  {

    //涂上容器 这会将油漆转移到任何这个容器的小孩的轻量级组件
    super.paint(g);

    //返回这个组件的图形上下文，它可以让你绘制在组件上。
    // 使用此方法获得<代码>图形< /代码>对象和然后调用该对象上的操作以绘制该组件。
    grphCanvas = jpnlDraw.getGraphics();

    //  开始制图
//    DrawFigures();
  }


  /**
   *  开始制图(加载数据)
   *  Draw figures.
   */
  private void DrawFigures(List list) throws Exception {

    //点位集合信息
//    List<DPointEntity>      dPointList      = JSON.parseArray(map.get("pointList").toString(),DPointEntity.class);
//    List<DCrossCostEntity>  dCrossCostList  = JSON.parseArray(map.get("dCrossCostList").toString(),DCrossCostEntity.class);
//    //拉线集合信息
//    List<DDrawLineEntity>   drawLineList    = JSON.parseArray(map.get("laxianList").toString(),DDrawLineEntity.class);
//
    List<DPointEntity>      dPointList      = (List<DPointEntity>) list.get(0);      // 点位集合信息
    List<DDrawLineEntity>   drawLineList    = (List<DDrawLineEntity>) list.get(1);   // 拉线集合信息
    List<DCrossCostEntity>  dCrossCostList  = (List<DCrossCostEntity>) list.get(2);  // 跨越物集合信息
    projectName = list.get(3).toString();

    float minLngNum = minLng(dPointList);
    float maxLatNum = maxLat(dPointList);

    float maxDXFWidth = 0;
    float maxDXFHeight = 0;
    float windowDXFWidth = 340;
    float windowDXFHeight = 595;
    //点位经纬度转换

    for (int i = 0; i < dPointList.size(); i++) {

      float lng = dPointList.get(i).getPPInputlongitude().floatValue();
      float lat = dPointList.get(i).getPPInputlatitude().floatValue();

      float public_X = (lng-minLngNum)*zoomNum+RectWidth+wuchaData;
      float public_Y = (maxLatNum-lat)*zoomNum+wuchaData;

      dPointList.get(i).setPPInputlongitude(BigDecimal.valueOf(public_X));
      dPointList.get(i).setPPInputlatitude(BigDecimal.valueOf(public_Y));


      //以下用于判断DXF宽度和高度用
      if(maxDXFWidth < dPointList.get(i).getPPInputlongitude().floatValue()+50){
        maxDXFWidth = dPointList.get(i).getPPInputlongitude().floatValue()+50;
      }
      if(maxDXFHeight < dPointList.get(i).getPPInputlatitude().floatValue()+220){
        maxDXFHeight = dPointList.get(i).getPPInputlatitude().floatValue()+220;
      }


    }

    //交叉跨越经纬度转换
    for (int i = 0; i < dCrossCostList.size(); i++) {
      float lng = dCrossCostList.get(i).getCCInputlongitude().floatValue();
      float lat = dCrossCostList.get(i).getCCInputlatitude().floatValue();

      float public_X = (lng-minLngNum)*zoomNum+RectWidth+wuchaData;
      float public_Y = (maxLatNum-lat)*zoomNum+wuchaData;

      dCrossCostList.get(i).setCCInputlongitude(BigDecimal.valueOf(public_X));
      dCrossCostList.get(i).setCCInputlatitude(BigDecimal.valueOf(public_Y));
    }

    //拉线经纬度转换
    for (int i = 0; i < drawLineList.size(); i++) {

      float lng = drawLineList.get(i).getDLLongitude().floatValue();
      float lat = drawLineList.get(i).getDLLatitude().floatValue();

      float public_X = (lng-minLngNum)*zoomNum+RectWidth+wuchaData;
      float public_Y = (maxLatNum-lat)*zoomNum+wuchaData;

      drawLineList.get(i).setDLLongitude(BigDecimal.valueOf(public_X));
      drawLineList.get(i).setDLLatitude(BigDecimal.valueOf(public_Y));
    }

    if(maxDXFWidth>tzMinWidth){
      windowDXFWidth=maxDXFWidth;
    }else{
      windowDXFWidth=tzMinWidth;
    }

    if(maxDXFHeight>tzMinHeight){
      windowDXFHeight=maxDXFHeight;
    }else{
      windowDXFHeight=tzMinHeight;
    }

      sgDrawWholeRectangle(0 , 0 , windowDXFWidth , windowDXFHeight); //  整体的矩形框
      sgIdentification();                                                     //  左上角图例标识
      sgDesign_info(dPointList , windowDXFWidth , windowDXFHeight);           //  右下角设计信息
      sgCompass(windowDXFWidth , windowDXFHeight);                            //  指北标识
      sgDrawPoint(dPointList , dCrossCostList);                               //  描点位（需要传递值）
      sgConnectionLine(dPointList);                                           //  画点位之间的线
      sgPushLine(dPointList , drawLineList);                                  //  画拉线
      sgDescriptionInfo(list , windowDXFWidth , windowDXFHeight);             //  左下角描述信息

//      sgDrawPixel();      //  画像素
//      sgDrawLine();       //  画直线
//      sgDrawPolyline();   //  画折线
//      sgDrawRectangle();  //  画矩形
//      sgDrawCircle();     //  画圆 (大圆套实心小圆)
//      sgDrawEllipse();    //  画椭圆(大椭圆套实心小椭圆)
//      sgDrawArc();        //  画圆弧
//      sgDrawPolygon();    //  画多边形
//      sgDrawBezier();     //  画贝塞尔曲线
//      sgDraw3DFace();     //  画3面
   /* }
    else if (sgStr.compareTo(strPixel) == 0)    //  单个点击项生成单个图形
      sgDrawPixel();
    else if (sgStr.compareTo(strLine) == 0)
      sgDrawLine();
    else if (sgStr.compareTo(strPolyline) == 0)
      sgDrawPolyline();
    else if (sgStr.compareTo(strRectangle) == 0)
      sgDrawRectangle();
    else if (sgStr.compareTo(strCircle) == 0)
      sgDrawCircle();
    else if (sgStr.compareTo(strEllipse) == 0)
      sgDrawEllipse();
    else if (sgStr.compareTo(strArc) == 0)
      sgDrawArc();
    else if (sgStr.compareTo(strPolygon) == 0)
      sgDrawPolygon();
    else if (sgStr.compareTo(strBezier) == 0)
      sgDrawBezier();
    else if (sgStr.compareTo(str3DFace) == 0)
      sgDraw3DFace();
    else
      sgDrawText();*/
  }





  /**
   *  加入文本
   * Draw a text.
   */
  public void sgDrawText() {
    grphCanvas.setColor(sgTextColor);
    grphCanvas.drawString(sgStr, 10, jpnlDraw.getHeight()/2);
  }


  /**
   *  像素
   * Draw a pixel.
  */
  public void sgDrawPixel() {
    int x=25, y=200;
    Color cl = Color.yellow;
    if (grphCanvas != null) {
      grphCanvas.setColor(cl);
      grphCanvas.drawString(strPixel, x-10, y-3);
      grphCanvas.drawLine(x, y, x, y);
    }
    if (Xprt!= null) {
      DXFLayer Layer = new DXFLayer(strPixel);
      Xprt.setCurrentLayer(Layer);
      DXFData Dt = new DXFData();
      Dt.LayerName = Layer.getName();
      Dt.Color = Constants.convertColorRGBToDXF(cl);
      Dt.Point = new DXFPoint(x, -y, 0);
      Xprt.addPixel(Dt);
      Dt.Point.setTo(x - 10, -(y - 3), 0);
      Dt.Point1 = new DXFPoint(Dt.Point.X, Dt.Point.Y, 0);
      Dt.FHeight = 10;
      Dt.HAlign = 1;
      Dt.Text = new String(strPixel);
      Xprt.addText(Dt);
      Dt = null;
    }
  }

  /**
   *  米勒投影（经纬度转平面坐标）
   *
   * @param lat
   * @param lon
   * @return
   */
  public static double[] MillierConvertion(double lat, double lon)
  {
    double L = 6381372 * Math.PI * 2;//地球周长
    double W=L;// 平面展开后，x轴等于周长
    double H=L/2;// y轴约等于周长一半
    double mill=2.3;// 米勒投影中的一个常数，范围大约在正负2.3之间
    double x = lon * Math.PI / 180;// 将经度从度数转换为弧度
    double y = lat * Math.PI / 180;// 将纬度从度数转换为弧度
    y=1.25 * Math.log( Math.tan( 0.25 * Math.PI + 0.4 * y ) );// 米勒投影的转换
    // 弧度转为实际距离
    x = ( W / 2 ) + ( W / (2 * Math.PI) ) * x;
    y = ( H / 2 ) - ( H / ( 2 * mill ) ) * y;
    double[] result=new double[2];
    result[0]=x;
    result[1]=y;
    return result;
  }


  //获取最小的经度
  public float minLng(List<DPointEntity> dPointList){
    float temp=180;
    for(int i = 0; i < dPointList.size(); i++){
      float lng=dPointList.get(i).getPPInputlongitude().floatValue();
      if(temp > lng){
        temp=lng;
      }
    }
    return temp;
  }
  //获取最大维度
  public float maxLat(List<DPointEntity> dPointList){
    float temp=0;
    for(int i = 0; i < dPointList.size(); i++){
      float lat=dPointList.get(i).getPPInputlatitude().floatValue();
      if(temp < lat){
        temp=lat;
      }
    }
    return temp;
  }



  /**
   *  描点位
   */
public void sgDrawPoint(List<DPointEntity> dPointList , List<DCrossCostEntity> dCrossCostList){

  //点位集合信息
//  List<DPointEntity> dPointList = JSON.parseArray(map.get("pointList").toString(),DPointEntity.class);
    Color cl = Color.black;

    DXFLayer Layer = new DXFLayer(strRectangle);
    Xprt.setCurrentLayer(Layer);
    DXFData Dt = new DXFData();
    Dt.LayerName = Layer.getName();
    Dt.Color = (Constants.convertColorRGBToDXF(cl));

  for (int i = 0; i < dPointList.size(); i++) {

    float x = dPointList.get(i).getPPInputlongitude().floatValue();//经度
    float y = dPointList.get(i).getPPInputlatitude().floatValue();//纬度

    Dt.Point = new DXFPoint(x, y, 0);

      //新建杆塔
    if(dPointList.get(i).getPPName().equals("杆塔")){
        sgDrawTower(x,y,false , dPointList.get(i).getPPCode(),dPointList.get(i).getPPBar().setScale(0).intValue());
    }else if (dPointList.get(i).getPPName().equals("搭火点")){
        sgDrawFirePoint(x,y,false, dPointList.get(i).getPPCode());
    }else if (dPointList.get(i).getPPName().equals("下户点")){
        sgDrawLowerHouseholdPoint(x,y,false, dPointList.get(i).getPPCode());
    }else if (dPointList.get(i).getPPName().equals("表箱")){
        sgDrawTableBox(x,y,false, dPointList.get(i).getPPCode());
    }else if (dPointList.get(i).getPPName().equals("柱上变压器")){
        sgDrawTransformer(x , y ,false, dPointList.get(i).getPPCode());
    }/*else{
      sgDrawStrideAcross( dCrossCostList , dPointList );
    }*/
  }

  if(dCrossCostList.size()!=0 && dCrossCostList!=null){
    for (int i = 0; i < dCrossCostList.size(); i++) {

//      float x = dCrossCostList.get(i).getCCInputlongitude().floatValue();
//      float y = dCrossCostList.get(i).getCCInputlatitude().floatValue();
      sgDrawStrideAcross(dCrossCostList , dPointList);

    }
  }


  }




  /**
   *  杆塔
   */
  public void sgDrawTower(float x , float y , Boolean tof , String PPCode , int PPBar){

//    int byx11=20, byy21=-100, byx21=30, byy22=-100,radius=10;
    int radius=10;
    Color cl = Color.black;

    DXFLayer Layer = new DXFLayer(strRectangle);
    Xprt.setCurrentLayer(Layer);
    DXFData Dt = new DXFData();
    Dt.LayerName = Layer.getName();
    Dt.Color = (Constants.convertColorRGBToDXF(cl));

    Dt.Point = new DXFPoint(x, -y, 0);
    Dt.Radius = radius;
    Xprt.addCircle(Dt);
//    Dt.SelfType = HatchBoundaryType.hbtCircle;
//    Dt.StartAngle = 0;
//    Dt.EndAngle = 360;
//    Xprt.addHatch(Dt);

    Dt.FHeight = 8;
    Dt.Point.setTo(x-3, -y-2, 0);
    Dt.Text = new String(String.valueOf(PPBar));
    Xprt.addText(Dt);

    Dt.FHeight = 8;
    Dt.Point.setTo(x, -y+radius, 0);
    Dt.Text = new String(PPCode);
    Xprt.addText(Dt);
    Dt = null;
}


/**
 *  搭火点
 */
public void sgDrawFirePoint(float x , float y , Boolean tof, String PPCode){

//  int byx11=20, byy21=-100, byx21=30, byy22=-100,radius=10;
  int radius=10;
  Color cl = Color.black;

  DXFLayer Layer = new DXFLayer(strRectangle);
  Xprt.setCurrentLayer(Layer);
  DXFData Dt = new DXFData();
  Dt.LayerName = Layer.getName();
  Dt.Color = (Constants.convertColorRGBToDXF(cl));

  Dt.Point = new DXFPoint(x, -y, 0);
  Dt.Radius = radius;
  Xprt.addCircle(Dt);
  Dt.Radius = Dt.Radius / 2;
  Dt.SelfType = HatchBoundaryType.hbtCircle;
  Dt.StartAngle = 0;
  Dt.EndAngle = 360;
  Xprt.addHatch(Dt);
  Dt.FHeight = 8;
  Dt.Point.setTo(x, -y+radius, 0);
  Dt.Text = new String(PPCode);
  Xprt.addText(Dt);


}


/**
 *  下户点
 */
public void sgDrawLowerHouseholdPoint(float x, float y , Boolean tof, String PPCode){

  int byx11=20, byy21=-100, byx21=30, byy22=-100,radius=10;
//  int radius=10 , h=28;
  Color cl = Color.black;

  DXFLayer Layer = new DXFLayer(strRectangle);
  Xprt.setCurrentLayer(Layer);
  DXFData Dt = new DXFData();
  Dt.LayerName = Layer.getName();
  Dt.Color = (Constants.convertColorRGBToDXF(cl));


//  Dt.Point = new DXFPoint(x+byx11+135, -(y+byy21+radius+140), 0);
//  Dt.Point1 = new DXFPoint(x+byx11+198, -(y+byy21+radius+155), 0);

//  Dt.Point = new DXFPoint(x+155, -(y+40), 0);
//  Dt.Point1 = new DXFPoint(x+218, -(y+65), 0);

  Dt.Point = new DXFPoint(x-30, -y-7, 0);
  Dt.Point1 = new DXFPoint(x+13, -y+8, 0);

  Xprt.addRectangle(Dt);

//  Dt.Point = new DXFPoint(x+byx11+175, -(y+byy22+radius+140), 0);
//  Dt.Point1 = new DXFPoint(x+byx11+175, -(y+byy22+radius+155), 0);

//  Dt.Point = new DXFPoint(x+195, -(y+50), 0);
//  Dt.Point1 = new DXFPoint(x+195, -(y+65), 0);

  Dt.Point = new DXFPoint(x-10, -y-7, 0);
  Dt.Point1 = new DXFPoint(x-10, -y+8, 0);
  Xprt.addLine(Dt);

  Dt.FHeight = 6;
//  Dt.Point.setTo(x+byx11+136, -(y+byy21+radius+150), 0);
//  Dt.Point.setTo(x+156, -(y+60), 0);
  Dt.Point.setTo(x-29, -y-5, 0);
  Dt.Text = new String("名称");
  Xprt.addText(Dt);

  Dt.FHeight = 6;
//  Dt.Point.setTo(x+byx11+176, -(y+byy21+radius+150), 0);
//  Dt.Point.setTo(x+196, -(y+60), 0);
  Dt.Point.setTo(x-11, -y-5, 0);
  Dt.Text = new String("数量");
  Xprt.addText(Dt);

  Dt.FHeight = 8;
//  Dt.Point.setTo(x+byx11+199, -(y+byy22+radius+150), 0);
//  Dt.Point.setTo(x+219, -(y+60), 0);
  Dt.Point.setTo(x-5, -y+10, 0);
  Dt.Text = new String(PPCode);
  Xprt.addText(Dt);

}


/**
 *  表箱
 */
public void sgDrawTableBox(float x, float y, Boolean tof, String PPCode){

  int byx11=20, byy21=-100, byx21=30, byy22=-100,radius=10;
  Color cl = Color.black;

  DXFLayer Layer = new DXFLayer(strRectangle);
  Xprt.setCurrentLayer(Layer);
  DXFData Dt = new DXFData();
  Dt.LayerName = Layer.getName();
  Dt.Color = (Constants.convertColorRGBToDXF(cl));

//  Dt.Point = new DXFPoint(x+byx11+0, -(y+byy21+radius+140), 0);
//  Dt.Point1 = new DXFPoint(x+byx11+30, -(y+byy21+radius+155), 0);

//  Dt.Point = new DXFPoint(x+20, -(y+50), 0);
//  Dt.Point1 = new DXFPoint(x+50, -(y+65), 0);

  Dt.Point = new DXFPoint(x-15, -y+7, 0);
  Dt.Point1 = new DXFPoint(x+15, -y-8, 0);
  Xprt.addRectangle(Dt);

  Dt.FHeight = 6;
//  Dt.Point.setTo(x+byx11+0, -(y+byy21+radius+150), 0);
//  Dt.Point.setTo(x+20, -(y+60), 0);
  Dt.Point.setTo(x-5, -y-5, 0);
  Dt.Text = new String("户表");
  Xprt.addText(Dt);

  Dt.FHeight = 8;
//  Dt.Point.setTo(x+byx21+30, -(y+byy22+radius+150), 0);
//  Dt.Point.setTo(x+60, -(y+60), 0);
  Dt.Point.setTo(x, -y+10, 0);
  Dt.Text = new String(PPCode);
  Xprt.addText(Dt);

}


/**
 *  柱上变压器
 */
public void sgDrawTransformer(float x , float y , Boolean tof, String PPCode){

  int byx11=20, byy21=-100, byx21=30, byy22=-100,radius=10;
  Color cl = Color.black;

  DXFLayer Layer = new DXFLayer(strRectangle);
  Xprt.setCurrentLayer(Layer);
  DXFData Dt = new DXFData();
  Dt.LayerName = Layer.getName();
  Dt.Color = (Constants.convertColorRGBToDXF(cl));

//  Dt.Point = new DXFPoint(x+byx11+radius, -(y+byy21+radius), 0);
//  Dt.Point = new DXFPoint(x+30, -(y-90), 0);
  Dt.Point = new DXFPoint(x-5, -y, 0);
  Dt.Radius = radius;
  Dt.SelfType = HatchBoundaryType.hbtCircle;
  Dt.StartAngle = 0;
  Dt.EndAngle = 360;
  Xprt.addHatch(Dt);
  Xprt.addCircle(Dt);

//  Dt.Point = new DXFPoint(x+byx21+radius, -(y+byy22+radius), 0);
//  Dt.Point = new DXFPoint(x+40, -(y-90), 0);
  Dt.Point = new DXFPoint(x+5, -y, 0);
  Dt.Radius = radius;
  Xprt.addCircle(Dt);

//  Dt.Point.setTo(x+byx21+30, -(y+byy22+radius+3), 0);
//  Dt.Point.setTo(x+60, -(y-87), 0);
  Dt.Point.setTo(x, -y+17, 0);
  Dt.FHeight = 8;
  Dt.Text = new String(PPCode);
  Xprt.addMText(Dt);

}


/**
 *  跨越物
 */
public void sgDrawStrideAcross(List<DCrossCostEntity> dCrossCostList , List<DPointEntity> dPointList){
//  public void sgDrawStrideAcross(float x , float y){


  Color cl = Color.black;

  DXFLayer Layer = new DXFLayer(strRectangle);
  Xprt.setCurrentLayer(Layer);
  DXFData Dt = new DXFData();
  Dt.LayerName = Layer.getName();
  Dt.Color = (Constants.convertColorRGBToDXF(cl));

  if(dCrossCostList.size()!=0 && dCrossCostList !=null) {

    DCrossCostEntity dCrossCost = new DCrossCostEntity();
    DPointEntity dPointFirst = new DPointEntity();//上联点位对象
    DPointEntity dPointSecond = new DPointEntity();//下联点位对象

    float x_cross = 0 ;
    float y_cross = 0 ;
    int cross_type = 0;
    for (int i = 0; i < dPointList.size(); i++) {
//      dPoint = dPointList.get(i);
      //点位上联与交叉跨越上联点位
      for (int j = 0; j < dCrossCostList.size(); j++) {
        if (dPointList.get(i).getPPUpguid()!=null && dPointList.get(i).getGuid().equals(dCrossCostList.get(j).getCCUpguid())) {
          dPointFirst = dPointList.get(i);
        }
        if (dPointList.get(i).getPPUpguid()!=null && dPointList.get(i).getGuid().equals(dCrossCostList.get(j).getCCDownguid())) {
          dPointSecond = dPointList.get(i);
        }
//        dCrossCost = dCrossCostList.get(j);
        x_cross = dCrossCostList.get(j).getCCInputlongitude().floatValue();//经度
        y_cross = dCrossCostList.get(j).getCCInputlatitude().floatValue();//纬度
        cross_type = Integer.parseInt(dCrossCostList.get(j).getCType().toString());
      }
    }

    String crossName = getCrossType(cross_type);
        //上联点位和下联点位
        if (dPointFirst.getPPInputlongitude().equals(dPointSecond.getPPInputlongitude())) {

          //  第一根横线(155,-13) (177,-13)
          Dt.Point = new DXFPoint(x_cross, -y_cross, 0);//x+155,-y+13
          Dt.Point1 = new DXFPoint(x_cross + 22, -y_cross, 0);//x+177,-y+13
          Xprt.addLine(Dt);

          Dt.Point = new DXFPoint(x_cross + 12, -y_cross + 4, 0);//x+167,-y+17
          Dt.Point1 = new DXFPoint(x_cross + 12, -y_cross, 0);//x+167,-y+13
          Xprt.addLine(Dt);

          Dt.Point = new DXFPoint(x_cross+12, -y_cross + 4, 0);//x+155,-y+17
          Dt.Point1 = new DXFPoint(x_cross+22, -y_cross, 0);//x+155,-y+13
          Xprt.addLine(Dt);

          // 第二根横线(186,-13) (208,-13)
          Dt.Point = new DXFPoint(x_cross + 31, -y_cross, 0);//x+186,-y+13
          Dt.Point1 = new DXFPoint(x_cross + 53, -y_cross, 0);//x+208,-y+13
          Xprt.addLine(Dt);

          Dt.Point = new DXFPoint(x_cross + 41, -y_cross + 4, 0);//x+196,-y+17
          Dt.Point1 = new DXFPoint(x_cross + 41, -y_cross, 0);//x+196,-y+13
          Xprt.addLine(Dt);

          Dt.Point = new DXFPoint(x_cross + 41, -y_cross + 4, 0);//x+196,-y+17
          Dt.Point1 = new DXFPoint(x_cross + 31, -y_cross, 0);//x+186,-y+13
          Xprt.addLine(Dt);

          //添加文字
          Dt.Point.setTo(x_cross + 53, -y_cross, 0);
          Dt.FHeight = 8;
          Dt.Text = new String(crossName);
          Xprt.addMText(Dt);

        }else if(dPointFirst.getPPInputlatitude().equals(dPointSecond.getPPInputlatitude())){
          //  第一根横线(155,-13) (177,-13)
          Dt.Point = new DXFPoint(x_cross, -y_cross, 0);//x+155,-y+13
          Dt.Point1 = new DXFPoint(x_cross , -y_cross+ 22, 0);//x+177,-y+13
          Xprt.addLine(Dt);

          Dt.Point = new DXFPoint(x_cross+4 , -y_cross + 16, 0);//x+167,-y+17
          Dt.Point1 = new DXFPoint(x_cross , -y_cross+ 12, 0);//x+167,-y+13
          Xprt.addLine(Dt);

          Dt.Point = new DXFPoint(x_cross+ 4, -y_cross , 0);//x+155,-y+17
          Dt.Point1 = new DXFPoint(x_cross, -y_cross, 0);//x+155,-y+13
          Xprt.addLine(Dt);

          // 第二根横线(186,-13) (208,-13)
          Dt.Point = new DXFPoint(x_cross , -y_cross+ 31, 0);//x+186,-y+13
          Dt.Point1 = new DXFPoint(x_cross , -y_cross+ 53, 0);//x+208,-y+13
          Xprt.addLine(Dt);

          Dt.Point = new DXFPoint(x_cross + 4, -y_cross + 45, 0);//x+196,-y+17
          Dt.Point1 = new DXFPoint(x_cross , -y_cross+ 41, 0);//x+196,-y+13
          Xprt.addLine(Dt);

          Dt.Point = new DXFPoint(x_cross + 4, -y_cross + 44, 0);//x+196,-y+17
          Dt.Point1 = new DXFPoint(x_cross , -y_cross+ 31, 0);//x+186,-y+13
          Xprt.addLine(Dt);

          //添加文字
          Dt.Point.setTo(x_cross , -y_cross+ 53, 0);
          Dt.FHeight = 8;
          Dt.Text = new String(crossName);
          Xprt.addMText(Dt);
        }else{
          float k=
                  (dPointSecond.getPPInputlatitude().floatValue()-dPointFirst.getPPInputlatitude().floatValue())
                          /(dPointSecond.getPPInputlongitude().floatValue()-dPointFirst.getPPInputlongitude().floatValue());

//          float k=
//                  (dPointFirst.getPPInputlatitude().floatValue()-dPointSecond.getPPInputlatitude().floatValue())
//                          /(dPointFirst.getPPInputlongitude().floatValue()-dPointSecond.getPPInputlongitude().floatValue());

          float b=
                  dPointSecond.getPPInputlatitude().floatValue()-k*dPointSecond.getPPInputlongitude().floatValue();
          sgDrawMarker(k,b,x_cross,y_cross,crossName);
        }
//      }
//    }
  }

}


/**
 *  跨越物类型
 */
public String getCrossType(int ctype){
    switch (ctype){
      case 100:
        return "河流";
      case 101:
        return "房屋";
      case 102:
        return "电力线路";
      case 103:
        return "公路";
      case 104:
        return "通讯线路";
      case 105:
        return "铁路";
      default:
        return "";
    }



}


/**
 *
 * 其余角度的跨越物
 */
public void sgDrawMarker(float k , float b1 , float x , float y , String crossName){

  Color cl = Color.black;

  DXFLayer Layer = new DXFLayer(strRectangle);
  Xprt.setCurrentLayer(Layer);
  DXFData Dt = new DXFData();
  Dt.LayerName = Layer.getName();
  Dt.Color = (Constants.convertColorRGBToDXF(cl));

  float h1=10;
  float h2=20;
  float h3=35;
  float h4=5;
  float k2=-1/k;//与线路垂直的线段的斜率
  float b2=y-k2*x;
//  (k2,b2,h1,x,y);

  //第一次
  float a=1+k2*k2;
  float bb=2*k2*(b2-y)-2*x;
  float c=x*x+(b2-y)*(b2-y)-h1*h1;
  float xc1=(float)(-1*bb+Math.sqrt(bb*bb-4*a*c))/(2*a);
  float xc2=(float)(-1*bb-Math.sqrt(bb*bb-4*a*c))/(2*a);
  float yc1=k2*xc1+b2;
  float yc2=k2*xc2+b2;
  float b3=yc1-k2*xc1;
  float b4=yc2-k2*xc2;

  //第二次
  float c2=x*x+(b2-y)*(b2-y)-h2*h2;
  float xc12=(float)(-1*bb+Math.sqrt(bb*bb-4*a*c2))/(2*a);
  float xc22=(float)(-1*bb-Math.sqrt(bb*bb-4*a*c2))/(2*a);
  float yc12=k2*xc12+b2;
  float yc22=k2*xc22+b2;
  float b32=yc12-k2*xc12;
  float b42=yc22-k2*xc22;

  //第三次
  float c3=x*x+(b2-y)*(b2-y)-h3*h3;
  float xc13=(float)(-1*bb+Math.sqrt(bb*bb-4*a*c3))/(2*a);
  float xc23=(float)(-1*bb-Math.sqrt(bb*bb-4*a*c3))/(2*a);
  float yc13=k2*xc13+b2;
  float yc23=k2*xc23+b2;
  float b33=yc13-k2*xc13;
  float b43=yc23-k2*xc23;

  //第四次
  float b444=yc12-k*xc12;
//  k,b4,h4,point2.x1,point2.y1);

  float a4=1+k*k;
  float bb4=2*k*(b444-yc12)-2*xc12;
  float c4=xc12*xc12+(b444-yc12)*(b444-yc12)-h4*h4;
  float xc14=(float)(-1*bb4+Math.sqrt(bb4*bb4-4*a4*c4))/(2*a4);
  float xc24=(float)(-1*bb4-Math.sqrt(bb4*bb4-4*a4*c4))/(2*a4);
  float yc14=k*xc14+b444;
  float yc24=k*xc24+b444;
  float b34=yc14-k*xc14;
  float b44=yc24-k*xc24;

  //第五次
  float b455=yc22-k*xc22;
  float a5=1+k*k;
  float bb5=2*k*(b455-yc22)-2*xc22;
  float c5=xc22*xc22+(b455-yc22)*(b455-yc22)-h4*h4;
  float xc15=(float)(-1*bb5+Math.sqrt(bb5*bb5-4*a5*c5))/(2*a5);
  float xc25=(float)(-1*bb5-Math.sqrt(bb5*bb5-4*a5*c5))/(2*a5);
  float yc15=k*xc15+b455;
  float yc25=k*xc25+b455;
  float b35=yc15-k*xc15;
  float b45=yc25-k*xc25;


  //  第一根横线(155,-13) (177,-13)
  Dt.Point = new DXFPoint(xc1, -yc1, 0);//x+155,-y+13
  Dt.Point1 = new DXFPoint(xc13 , -yc13, 0);//x+177,-y+13
  Xprt.addLine(Dt);
  //竖线
  Dt.Point = new DXFPoint(xc12, -yc12, 0);//x+167,-y+17
  Dt.Point1 = new DXFPoint(xc24, -yc24, 0);//x+167,-y+13
  Xprt.addLine(Dt);
  //斜线
  Dt.Point = new DXFPoint(xc24, -yc24 , 0);//x+155,-y+17
  Dt.Point1 = new DXFPoint(xc1, -yc1, 0);//x+155,-y+13
  Xprt.addLine(Dt);

  // 第二根横线(186,-13) (208,-13)
  Dt.Point = new DXFPoint(xc2 , -yc2, 0);//x+186,-y+13
  Dt.Point1 = new DXFPoint(xc23, -yc23, 0);//x+208,-y+13
  Xprt.addLine(Dt);
    //竖线
  Dt.Point = new DXFPoint(xc22, -yc22, 0);//x+196,-y+17
  Dt.Point1 = new DXFPoint(xc25, -yc25, 0);//x+196,-y+13
  Xprt.addLine(Dt);
    //斜线
  Dt.Point = new DXFPoint(xc25, -yc25, 0);//x+196,-y+17
  Dt.Point1 = new DXFPoint(xc2, -yc2, 0);//x+186,-y+13
  Xprt.addLine(Dt);

  //添加文字
  Dt.Point.setTo(xc23-60, -yc23, 0);
  Dt.FHeight = 8;
  Dt.Text = new String(crossName);
  Xprt.addMText(Dt);

}


/**
 *  画点位之间的线
 */
public void sgConnectionLine(List<DPointEntity> dPointList){

//  List<DPointEntity> dPointList = JSON.parseArray(map.get("pointList").toString(),DPointEntity.class);
  for (int i = 0; i < dPointList.size(); i++) {
      for (int j = 0; j < dPointList.size(); j++) {
          //  是否有下联
          if(dPointList.get(i).getGuid().equals(dPointList.get(j).getPPUpguid())){
              //上联点位经纬度
              float x1 = dPointList.get(i).getPPInputlongitude().floatValue();
              float y1 = dPointList.get(i).getPPInputlatitude().floatValue();
              //下联经纬度
              float x2 = dPointList.get(j).getPPInputlongitude().floatValue();
              float y2 = dPointList.get(j).getPPInputlatitude().floatValue();
              float z = 0;

              if (dPointList.get(j).getPPVoltage().equals("1")){//10kv
                  sgDrawLigature_10kv(x1,y1,x2,y2,false);
              }else if(dPointList.get(j).getPPVoltage().equals("2")){//380v
                  sgDrawLigature_380v(x1,y1,x2,y2,false,z);
              }else if(dPointList.get(j).getPPVoltage().equals("3")){//220v
                  sgDrawLigature_220v(x1,y1,x2,y2,false,z);
              }

              //档距显示
            if(dPointList.get(j).getPPAutospan() !=null && !dPointList.get(j).getPPAutospan().equals("")) {
                sgDrawTextByLine(x1, y1, x2, y2, (float) Math.ceil(dPointList.get(j).getPPAutospan().floatValue()));
            }
          }
      }
  }

}



  /**
   *  10kv线路连线
   */
  public void sgDrawLigature_10kv(float x1 ,float y1 ,float x2,float y2 ,Boolean tof) {
    int byx11=20, byy21=-100, byx21=30, byy22=-100,radius=10;
    Color cl = Color.black;
    if (Xprt!= null) {
      //用此作图
      DXFLayer Layer = new DXFLayer(strLine);
      Xprt.setCurrentLayer(Layer);
      DXFData Dt = new DXFData();
      Dt.LayerName = Layer.getName();
      Dt.Color = (Constants.convertColorRGBToDXF(cl));

//      Dt.Point = new DXFPoint(x1+byx11-4, -(y1+byy22+radius+35), 0);
//      Dt.Point1 = new DXFPoint(x2+byx11-7, -(y2+byy22+radius+35), 0);

      Dt.Point = new DXFPoint(x1, -y1, 0);
      Dt.Point1 = new DXFPoint(x2, -y2, 0);

      Xprt.addLine(Dt);

      if(y1==y2){
          float xx1=(x2+x1)/2;
          int hh1=10;

          //  1列
        Dt.Point = new DXFPoint(xx1, -y1-hh1, 0);
        Dt.Point1 = new DXFPoint(xx1,-y1+hh1, 0);

          Xprt.addLine(Dt);
//
//          //  2列
          Dt.Point = new DXFPoint(xx1-5, -y1-hh1, 0);
          Dt.Point1 = new DXFPoint(xx1-5,-y1+hh1, 0);
          Xprt.addLine(Dt);
//
//          //  3列
          Dt.Point = new DXFPoint(xx1+5, -y1-hh1, 0);
          Dt.Point1 = new DXFPoint(xx1+5,-y2+hh1, 0);
          Xprt.addLine(Dt);

      }else if(x1==x2){

        float yy1=(y2+y1)/2;
        int hh1=10;

        //  1列
        Dt.Point = new DXFPoint(x1-hh1, -yy1, 0);
        Dt.Point1 = new DXFPoint(x1+hh1,-yy1, 0);
        Xprt.addLine(Dt);
       //  2列
        Dt.Point = new DXFPoint(x1-hh1, -yy1-5, 0);
        Dt.Point1 = new DXFPoint(x1+hh1,-yy1-5, 0);
        Xprt.addLine(Dt);
       //  3列
        Dt.Point = new DXFPoint(x1-hh1, -yy1+5, 0);
        Dt.Point1 = new DXFPoint(x1+hh1,-yy1+5, 0);
        Xprt.addLine(Dt);

      }else {

        float k = (y1-y2)/(x1-x2);//两点位间的线的斜率
        float b=y1-k*x1;
        float k2=-1/k;            //与线路垂直的线段的斜率

        float yy2=(y1+y2)/2;      //线路中间点的y
        float xx2=(x1+x2)/2;      //线路中间点的x
        float b2=yy2-k2*xx2;

        int hh1=20;
        int hh2=5;

        float a=1+k*k;
        float bb=2*k*(b-yy2)-2*xx2;
        float c=xx2*xx2+(b-yy2)*(b-yy2)-hh2*hh2;

        float x10kv_1=(float)(-1*bb+Math.sqrt(bb*bb-4*a*c))/(2*a);
        float x10kv_2=(float)(-1*bb-Math.sqrt(bb*bb-4*a*c))/(2*a);

        float y10kv_1=k*x10kv_1+b;
        float y10kv_2=k*x10kv_2+b;

        float b3=y10kv_1-k2*x10kv_1;
        float b4=y10kv_2-k2*x10kv_2;

        //第一列
        sgDrawLines(k2,b2,hh1,xx2,yy2);
        //第二列
        sgDrawLines(k2,b3,hh1,x10kv_1,y10kv_1);// k,x,b影响y的坐标值
        //第三列
        sgDrawLines(k2,b4,hh1,x10kv_2,y10kv_2);
      }

      Dt = null;
    }
  }



  /**
   *  380v线路连线
   */
  public void sgDrawLigature_380v(float x1 ,float y1 ,float x2,float y2 ,Boolean tof,float z) {
//    int x1=10, y1=180, x2=20, y2=40;
    int byx11=20, byy21=-100, byx21=30, byy22=-100,radius=10;
    Color cl = Color.black;
    if (Xprt!= null) {
      //用此作图
      DXFLayer Layer = new DXFLayer(strLine);
      Xprt.setCurrentLayer(Layer);
      DXFData Dt = new DXFData();
      Dt.LayerName = Layer.getName();
      Dt.Color = (Constants.convertColorRGBToDXF(cl));

      Dt.Point = new DXFPoint(x1, -y1, 0);
      Dt.Point1 = new DXFPoint(x2, -y2, 0);
      Xprt.addLine(Dt);

      if(y1==y2){
        float xx1=(x2+x1)/2;
        int hh1=10;

        //  1列
        Dt.Point = new DXFPoint(xx1, -y1-hh1, 0);
        Dt.Point1 = new DXFPoint(xx1,-y1+hh1, 0);
        Xprt.addLine(Dt);

        //  2列
        Dt.Point = new DXFPoint(xx1-5, -y1-hh1, 0);
        Dt.Point1 = new DXFPoint(xx1-5,-y1+hh1, 0);
        Xprt.addLine(Dt);

        //  3列
        Dt.Point = new DXFPoint(xx1+5, -y1-hh1, 0);
        Dt.Point1 = new DXFPoint(xx1+5,-y2+hh1, 0);
        Xprt.addLine(Dt);

        //  4列
        Dt.Point = new DXFPoint(xx1+10, -y1-hh1, 0);
        Dt.Point1 = new DXFPoint(xx1+10,-y2+hh1, 0);
        Xprt.addLine(Dt);

      }else if(x1==x2){

        float yy1=(y2+y1)/2;
        int hh1=10;

        //  1列
        Dt.Point = new DXFPoint(x1-hh1, -yy1, 0);
        Dt.Point1 = new DXFPoint(x1+hh1,-yy1, 0);
        Xprt.addLine(Dt);

        //  2列
        Dt.Point = new DXFPoint(x1-hh1, -yy1-5, 0);
        Dt.Point1 = new DXFPoint(x1+hh1,-yy1-5, 0);
        Xprt.addLine(Dt);

        //  3列
        Dt.Point = new DXFPoint(x1-hh1, -yy1+5, 0);
        Dt.Point1 = new DXFPoint(x1+hh1,-yy1+5, 0);
        Xprt.addLine(Dt);

        //  4列
        Dt.Point = new DXFPoint(x1-hh1, -yy1+10, 0);
        Dt.Point1 = new DXFPoint(x1+hh1,-yy1+10, 0);
        Xprt.addLine(Dt);

      }else {

        float k = (y1-y2)/(x1-x2);
        float b=y1-k*x1;
        float k2=-1/k;
        float yy2=(y1+y2)/2;
        float xx2=(x1+x2)/2;
        float b2=yy2-k2*xx2;
        int hh1=20;
        int hh2=5;



        float a=1+k*k;
        float bb=2*k*(b-yy2)-2*xx2;
        float c=xx2*xx2+(b-yy2)*(b-yy2)-hh2*hh2;
        float x380v_1=(float)(-1*bb+Math.sqrt(bb*bb-4*a*c))/(2*a);
        float x380v_2=(float)(-1*bb-Math.sqrt(bb*bb-4*a*c))/(2*a);
        float y380v_1=k*x380v_1+b;
        float y380v_2=k*x380v_2+b;
        float b3=y380v_1-k2*x380v_1;
        float b4=y380v_2-k2*x380v_2;

        //第一列
        sgDrawLines(k2,b2,hh1,xx2,yy2);
        //第二列
        sgDrawLines(k2,b3,hh1,x380v_1,y380v_1);
        //第三列
        sgDrawLines(k2,b4,hh1,x380v_2,y380v_2);

      }

      Dt = null;
    }
  }



  /**
   *  220v线路连线
   */
  public void sgDrawLigature_220v(float x1 ,float y1 ,float x2,float y2 ,Boolean tof,float z) {
//    int x1=10, y1=180, x2=20, y2=40;
    int byx11=20, byy21=-100, byx21=30, byy22=-100,radius=10;
    Color cl = Color.black;
    if (Xprt!= null) {
      //用此作图
      DXFLayer Layer = new DXFLayer(strLine);
      Xprt.setCurrentLayer(Layer);
      DXFData Dt = new DXFData();
      Dt.LayerName = Layer.getName();
      Dt.Color = (Constants.convertColorRGBToDXF(cl));

      Dt.Point = new DXFPoint(x1, -y1, 0);
      Dt.Point1 = new DXFPoint(x2, -y2, 0);
      Xprt.addLine(Dt);

      if(y1==y2){
        float xx1=(x2+x1)/2;
        int hh1=10;
        //  1列
        Dt.Point = new DXFPoint(xx1, -y1-hh1, 0);
        Dt.Point1 = new DXFPoint(xx1,-y1+hh1, 0);
        Xprt.addLine(Dt);
        //  2列
        Dt.Point = new DXFPoint(xx1-5, -y1-hh1, 0);
        Dt.Point1 = new DXFPoint(xx1-5,-y1+hh1, 0);
        Xprt.addLine(Dt);

      }else if(x1==x2){

        float yy1=(y2+y1)/2;
        int hh1=10;

        //  1列
        Dt.Point = new DXFPoint(x1-hh1, -yy1, 0);
        Dt.Point1 = new DXFPoint(x1+hh1,-yy1, 0);
        Xprt.addLine(Dt);
        //  2列
        Dt.Point = new DXFPoint(x1-hh1, -yy1-5, 0);
        Dt.Point1 = new DXFPoint(x1+hh1,-yy1-5, 0);
        Xprt.addLine(Dt);

      }else {

        float k = (y1-y2)/(x1-x2);
        float b=y1-k*x1;
        float k2=-1/k;
        float yy2=(y1+y2)/2;
        float xx2=(x1+x2)/2;
        float b2=yy2-k2*xx2;
        int hh1=20;
        int hh2=5;

        float a=1+k*k;
        float bb=2*k*(b-yy2)-2*xx2;
        float c=xx2*xx2+(b-yy2)*(b-yy2)-hh2*hh2;
        float x220v_1=(float)(-1*bb+Math.sqrt(bb*bb-4*a*c))/(2*a);
        float x220v_2=(float)(-1*bb-Math.sqrt(bb*bb-4*a*c))/(2*a);
        float y220v_1=k*x220v_1+b;
        float y220v_2=k*x220v_2+b;
        float b3=y220v_1-k2*x220v_1;
        float b4=y220v_2-k2*x220v_2;

        //第一列
        sgDrawLines(k2,b2,hh1,xx2,yy2);
        //第二列
        sgDrawLines(k2,b3,hh1,x220v_1,y220v_1);
      }

      Dt = null;
    }
  }




  /**
   *  线路非垂直角度画线
   *
   * @param k
   * @param b
   * @param h
   * @param x0
   * @param y0
   */
  public void sgDrawLines(float k , float b , float h , float x0 , float y0){

    float x1=(float) Math.sqrt(h*h/(4+4*k*k))+x0;
    float y1=k*x1+b;
    float x2=2*x0-x1;
    float y2=k*x2+b;


    Color cl = Color.black;
    if (Xprt!= null) {
      //用此作图
      DXFLayer Layer = new DXFLayer(strLine);
      Xprt.setCurrentLayer(Layer);
      DXFData Dt = new DXFData();
      Dt.LayerName = Layer.getName();
      Dt.Color = (Constants.convertColorRGBToDXF(cl));
      Dt.Point = new DXFPoint(x1, -y1, 0);
      Dt.Point1 = new DXFPoint(x2, -y2, 0);
      Xprt.addLine(Dt);
//      Dt.Point.setTo(x1, -(y2-20), 0);
//      Dt.FHeight = 10;
//      Dt.Text = new String();
//      Xprt.addText(Dt);
      Dt = null;
    }

  }



  public void sgDrawLines111(float k , float b , float h , float x0 , float y0){

    float x1=(float) Math.sqrt(h*h/(4+4*k*k))+x0;
    float y1=k*x1+b;
    float x2=2*x0-x1;
    float y2=k*x2+b;


    Color cl = Color.blue;
    if (Xprt!= null) {
      //用此作图
      DXFLayer Layer = new DXFLayer(strLine);
      Xprt.setCurrentLayer(Layer);
      DXFData Dt = new DXFData();
      Dt.LayerName = Layer.getName();
      Dt.Color = (Constants.convertColorRGBToDXF(cl));
      Dt.Point = new DXFPoint(x1, -y1, 0);
      Dt.Point1 = new DXFPoint(x2, -y2, 0);
      Xprt.addLine(Dt);
//      Dt.Point.setTo(x1, -(y2-20), 0);
//      Dt.FHeight = 10;
//      Dt.Text = new String();
//      Xprt.addText(Dt);
      Dt = null;
    }

  }


  /**
   *  档距显示
   *
   * @param ax1
   * @param ay1
   * @param ax2
   * @param ay2
   * @param text
   */
  public void sgDrawTextByLine(float ax1 , float ay1 , float ax2 , float ay2 , float text){
    //在线上放H处显示文字
    int h=10;
  Color cl = Color.black;
  if (Xprt!= null) {
    //用此作图
    DXFLayer Layer = new DXFLayer(strLine);
    Xprt.setCurrentLayer(Layer);
    DXFData Dt = new DXFData();
    Dt.LayerName = Layer.getName();
    Dt.Color = (Constants.convertColorRGBToDXF(cl));


    if(ax2!=ax1 && ay2!=ay1){
      float k=(-1)/((ay2-ay1)/(ax2-ax1));//算斜率
      float x1=(ax1+ax2)/2;
      float y1=(ay1+ay2)/2;
      float b=y1-k*x1;
      float ta=(h*h-x1*x1-(b-y1)*(b-y1))/(1+k*k);
      float tb=(k*b-k*y1-x1)/(1+k*k);
      float x2=(float)Math.sqrt(ta+tb*tb)-tb;
      float y2=k*x2+b;

      Dt.Point = new DXFPoint(x2-5, -y2-10, 0);
      Dt.Point.setTo(x2-5, -y2-10, 0);
      Dt.FHeight = 6;
      Dt.Text = new String(String.valueOf(text));
      Xprt.addText(Dt);

    }else{
      if(ax2==ax1){
        Dt.Point = new DXFPoint(ax1+h, (-ay2-ay1)/2, 0);
        Dt.Point.setTo(ax1+h, (-ay2-ay1)/2, 0);
        Dt.FHeight = 6;
        Dt.Text = new String(String.valueOf(text));
        Xprt.addText(Dt);

      }else if(ay2==ay1){
        Dt.Point = new DXFPoint((ax1+ax2)/2, -ay1-h, 0);
        Dt.Point.setTo((ax1+ax2)/2, -ay1-h, 0);
        Dt.FHeight = 6;
        Dt.Text = new String(String.valueOf(text));
        Xprt.addText(Dt);

      }
    }


    /*if(ax2!=ax1 && ay2!=ay1){
      float k=(-1)/((ay2-ay1)/(ax2-ax1));//算斜率
      float x1=(ax1+ax2)/2;
      float y1=(ay1+ay2)/2;
      float b=y1-k*x1;
      float ta=(h*h-x1*x1-(b-y1)*(b-y1))/(1+k*k);
      float tb=(k*b-k*y1-x1)/(1+k*k);
      float x2=(float)Math.sqrt(ta+tb*tb)-tb;
      float y2=k*x2+b;

      Dt.Point = new DXFPoint(x2, y2, 0);
      Dt.Point.setTo(x2, y2, 0);
      Dt.FHeight = 10;
      Dt.Text = new String(String.valueOf(text));
      Xprt.addText(Dt);

    }else{
      if(ax2==ax1){
        Dt.Point = new DXFPoint(ax1+h, (ay2+ay1)/2, 0);
        Dt.Point.setTo(ax1+h, (ay2+ay1)/2, 0);
        Dt.FHeight = 10;
        Dt.Text = new String(String.valueOf(text));
        Xprt.addText(Dt);

      }else if(ay2==ay1){
        Dt.Point = new DXFPoint((ax1+ax2)/2, ay1-h, 0);
        Dt.Point.setTo((ax1+ax2)/2, ay1-h, 0);
        Dt.FHeight = 10;
        Dt.Text = new String(String.valueOf(text));
        Xprt.addText(Dt);

      }
    }*/


    Dt = null;
  }



  }






  /**
   *  380v线路连线
   */
  public void sgDrawLigature_380v(float x1 ,float y1 ,float x2,float y2 ,Boolean tof) {
//    int x1=10, y1=180, x2=20, y2=40;
    Color cl = Color.blue;
    if (Xprt!= null) {
      //用此作图
      DXFLayer Layer = new DXFLayer(strLine);
      Xprt.setCurrentLayer(Layer);
      DXFData Dt = new DXFData();
      Dt.LayerName = Layer.getName();
      Dt.Color = (Constants.convertColorRGBToDXF(cl));
      Dt.Point = new DXFPoint(x1, -y1, 0);
      Dt.Point1 = new DXFPoint(x2, -y2, 0);
      Xprt.addLine(Dt);
      Dt.Point.setTo(x1, -(y2-20), 0);
      Dt.FHeight = 10;
      Dt.Text = new String(strLine);
      Xprt.addText(Dt);
      Dt = null;
    }
  }

  /**
   *  220v线路连线
   */
  public void sgDrawLigature_220v(float x1 ,float y1 ,float x2,float y2 ,Boolean tof) {
//    int x1=10, y1=180, x2=20, y2=40;
    Color cl = Color.blue;
    if (Xprt!= null) {
      //用此作图
      DXFLayer Layer = new DXFLayer(strLine);
      Xprt.setCurrentLayer(Layer);
      DXFData Dt = new DXFData();
      Dt.LayerName = Layer.getName();
      Dt.Color = (Constants.convertColorRGBToDXF(cl));
      Dt.Point = new DXFPoint(x1, -y1, 0);
      Dt.Point1 = new DXFPoint(x2, -y2, 0);
      Xprt.addLine(Dt);
      Dt.Point.setTo(x1, -(y2-20), 0);
      Dt.FHeight = 10;
      Dt.Text = new String(strLine);
      Xprt.addText(Dt);
      Dt = null;
    }
  }




/**
 *  画拉线
 */
public void sgPushLine(List<DPointEntity> dPointList , List<DDrawLineEntity> drawLineList){

  //拉线集合信息
//  List<DDrawLineEntity> drawLineList = JSON.parseArray(map.get("laxianList").toString(),DDrawLineEntity.class);
//  List<DPointEntity> dPointList = JSON.parseArray(map.get("pointList").toString(),DPointEntity.class);
  List<DPointEntity> list_1 = new ArrayList();

  //选出点位是塔杆且拉线数量大于0的杆塔
  for (int i = 0; i < dPointList.size(); i++) {
      if(dPointList.get(i).getPPName().equals("杆塔") && dPointList.get(i).getPPWirenum()>0){
        list_1.add(dPointList.get(i));
      }
  }



  for (int i = 0; i < list_1.size(); i++) {
      //杆塔经纬度
      float x1 = list_1.get(i).getPPInputlongitude().floatValue();
      float y1 = list_1.get(i).getPPInputlatitude().floatValue();

      //拉线经纬度
//      float xm2=0 ,ym2=0;
//      float xm3 =0,ym3=0;

    float x2 = 0 , y2 = 0;
    float x3 = 0 , y3 = 0;
      for (int j = i; j < drawLineList.size(); j++) {
          //一根杆塔只有一根拉线时
          if(list_1.get(i).getPPWirenum() ==1){
              if(list_1.get(i).getGuid().equals(drawLineList.get(j).getPPGuid())){

                x2 = drawLineList.get(j).getDLLongitude().floatValue();
                y2 = drawLineList.get(j).getDLLatitude().floatValue();

                drawLineTwoPoint(x1,y1,x2,y2);
              }

//            if(list_1.get(i).getPPWirenum() == 1){
//              drawLineTwoPoint(x1,y1,x2,y2);
//            }
          }
          //一根杆塔有一条以上的拉线时
          if(list_1.get(i).getPPWirenum()>1){
              if(list_1.get(i).getGuid().equals(drawLineList.get(j).getPPGuid())){

                x3 = drawLineList.get(j).getDLLongitude().floatValue();
                y3 = drawLineList.get(j).getDLLatitude().floatValue();

                drawLineTwoPoint(x1,y1,x3,y3);
              }

            //同一杆塔上有多条拉线时
//            if(list_1.get(i).getPPWirenum() > 1) {
//              drawLineTwoPoint(x1,y1,x3,y3);
//            }

          }

      }


//    if(list_1.get(i).getPPWirenum() == 1){
//        drawLineTwoPoint(x1,y1,x2,y2);
//    }
//    else{
//        drawLineNozero2(x1,y1,x2,y2);
//    }

    //同一杆塔上有多条拉线时
//    if(list_1.get(i).getPPWirenum() > 1) {
//        drawLineTwoPoint(x1,y1,x3,y3);
//    }

  }

 }


  /**
   *  一个杆塔上有多根拉线时
   */
  public void drawLineTwoPoint(float x1 , float y1 , float x2 , float y2){
      if(x1!=x2 && y1!=y2){
        drawLineNozero(x1,y1,x2,y2);
      }else{
        drawLineZero(x1,y1,x2,y2);
      }
  }

  /**
   * 杆塔无下联时的拉线位置
   *
   * @param x1
   * @param y1
   * @param x2
   * @param y2
   */
  public void drawLineNozero(float x1 , float y1 , float x2 , float y2){
    float k=(y1-y2)/(x1-x2);
    float b=y1-k*x1;
    float h=3;//延长线距离

    Color cl = Color.black;
    DXFLayer Layer = new DXFLayer(strRectangle);
    Xprt.setCurrentLayer(Layer);
    DXFData Dt = new DXFData();
    Dt.LayerName = Layer.getName();
    Dt.Color = (Constants.convertColorRGBToDXF(cl));

    //第一条线
    Dt.Point = new DXFPoint(x1, -y1, 0);
    Dt.Point1 = new DXFPoint(x2,-y2, 0);
    Xprt.addLine(Dt);

    //第二条线
    float laxk=-1/k;
    float laxb=y2-laxk*x2;
    float h2=8;//垂直线的一半

    float ta2=(h2*h2-x2*x2-(laxb-y2)*(laxb-y2))/(1+laxk*laxk);
    float tb2=(laxk*laxb-laxk*y2-x2)/(1+laxk*laxk);
    //垂直线的第一个点根据公式计算出来
    float laxx1=(float) Math.sqrt(ta2+tb2*tb2)-tb2;
    float laxy1=laxk*laxx1+laxb;
    float laxx2=x2+(x2-laxx1);
    float laxy2=laxk*laxx2+laxb;

    Dt.Point = new DXFPoint(laxx1, -laxy1, 0);
    Dt.Point1 = new DXFPoint(laxx2,-laxy2, 0);
    Xprt.addLine(Dt);

  }


  /**
   *斜率为0时
   *
   * @param x1
   * @param y1
   * @param x2
   * @param y2
   */
  public void drawLineZero(float x1 , float y1 , float x2 , float y2){
    Color cl = Color.black;
    DXFLayer Layer = new DXFLayer(strRectangle);
    Xprt.setCurrentLayer(Layer);
    DXFData Dt = new DXFData();
    Dt.LayerName = Layer.getName();
    Dt.Color = (Constants.convertColorRGBToDXF(cl));

    if(x1==x2){
        Dt.Point = new DXFPoint(x1, y1, 0);
        Dt.Point1 = new DXFPoint(x1,y1+20, 0);
        Xprt.addLine(Dt);

        Dt.Point = new DXFPoint(x1-10, y1+20, 0);
        Dt.Point1 = new DXFPoint(x1+10,y1+20, 0);
        Xprt.addLine(Dt);

    }else if(y1==y2){
        Dt.Point = new DXFPoint(x1, y1, 0);
        Dt.Point1 = new DXFPoint(x1+20,y1, 0);
        Xprt.addLine(Dt);

        Dt.Point = new DXFPoint(x1+20, y1-10, 0);
        Dt.Point1 = new DXFPoint(x1+20,y1+10, 0);
        Xprt.addLine(Dt);

      }
  }

  /**
   * 画拉线,两个点以上的时候,四象限画拉线用,象限点数最少的45度画拉线
   *
   * @param x1
   * @param y1
   * @param x2
   * @param y2
   */
  public void drawLineNozero2(float x1 , float y1 , float x2 , float y2){
    float k=(y1-y2)/(x1-x2);
    float laxx=x2;
    float laxy=y2;

    Color cl = Color.black;
    DXFLayer Layer = new DXFLayer(strRectangle);
    Xprt.setCurrentLayer(Layer);
    DXFData Dt = new DXFData();
    Dt.LayerName = Layer.getName();
    Dt.Color = (Constants.convertColorRGBToDXF(cl));

    //第一条线
    Dt.Point = new DXFPoint(x1, y1, 0);
    Dt.Point1 = new DXFPoint(laxx,laxy, 0);
    Xprt.addLine(Dt);

    //第二条线
    float laxk=-1/k;
    float laxb=laxy-laxk*laxx;
    float h2=10;//垂直线的一半
    float ta2=(h2*h2-laxx*laxx-(laxb-laxy)*(laxb-laxy))/(1+laxk*laxk);
    float tb2=(laxk*laxb-laxk*laxy-laxx)/(1+laxk*laxk);
    //垂直线的第一个点根据公式计算出来
    float laxx1 = (float) Math.sqrt(ta2+tb2*tb2)-tb2;
    float laxy1=laxk*laxx1+laxb;
    float laxx2=laxx+(laxx-laxx1);
    float laxy2=laxk*laxx2+laxb;

    Dt.Point = new DXFPoint(laxx1, laxy1, 0);
    Dt.Point1 = new DXFPoint(laxx2,laxy2, 0);
    Xprt.addLine(Dt);

  }


/**
 *  左下角描述信息
 */
public void sgDescriptionInfo(List list , float windowDXFWidth , float windowDXFHeight) {

//  int x1=550, y1=650, x2=1000, y2=520;
  int x1=550, y1=650, x2=1000, y2=(int)windowDXFHeight-480;

  //点位描述信息集合
//  String pointInfo = map.get("pointInfo").toString();
  String pointInfo = list.get(6).toString();

  Color cl = Color.black;
  DXFLayer Layer = new DXFLayer(strRectangle);
  Xprt.setCurrentLayer(Layer);
  DXFData Dt = new DXFData();
  Dt.LayerName = Layer.getName();
  Dt.Color = (Constants.convertColorRGBToDXF(cl));

  int ziSize=400;//长度超过400换行
  // var arr = svgSpec.split("。");
//  var arr = svgSpec;
  int n=getHangNum(pointInfo);
  System.err.println("信息描述行数=="+n);
  String tempStr="";
  int tempPx = 0;
  for(int i=0;i<pointInfo.length();i++){
    String str = pointInfo.substring(i,i+1);
    tempStr+=str;
    if(isChinese(str)){
      tempPx+=12;
    }else{
      tempPx+=8;
    }

    //  如果末尾是句号，则下一句换行
    if(str.equals("。")){
//      Dt.Point = new DXFPoint(30, 1000- 30*n-10, 0);//30,870,0
      Dt.Point = new DXFPoint(30, -y2+ 30*n-100, 0);//30,870,0
//      Dt.Point.setTo(30, 1000- 30*n-10, 0);
      Dt.Point.setTo(30, -y2+ 30*n-100, 0);
      Dt.FHeight = 10;
      Dt.Text = new String(tempStr);
      Xprt.addText(Dt);

      tempStr="";
      tempPx=0;
      n--;
    }else{
      if(tempPx > ziSize){
        //添加文字
//        Dt.Point = new DXFPoint(30, 1000- 30*n-10, 0);//30,870,0
//        Dt.Point.setTo(30, 1000- 30*n-10, 0);
        Dt.Point = new DXFPoint(30, -y2+ 30*n-100, 0);//30,870,0
        Dt.Point.setTo(30, -y2+ 30*n-100, 0);
        Dt.FHeight = 10;
        Dt.Text = new String(tempStr);
        Xprt.addText(Dt);

        tempStr="";
        tempPx=0;
        n--;
      }else if((i+1)==pointInfo.length()){
        //添加文字
//        Dt.Point = new DXFPoint(30, 1000- 30*n-10, 0);
//        Dt.Point.setTo(30, 1000- 30*n-10, 0);
        Dt.Point = new DXFPoint(30, -y2+ 30*n-100, 0);
        Dt.Point.setTo(30, -y2+ 30*n-100, 0);
        Dt.FHeight = 10;
        Dt.Text = new String(tempStr);
        Xprt.addText(Dt);

        tempStr="";
        tempPx=0;
        n--;
      }
    }
  }
}


  //获取描述行数
  public int getHangNum(String pointInfo){
    int ziSize=400;//长度超过400换行
    int tempPx=0;
//    var arr = svgSpec;
    int n=0;
    for(int i=0;i<pointInfo.length();i++){
      String str = pointInfo.substring(i,i+1);
      if(isChinese(str)){
        tempPx+=12;
      }else{
        tempPx+=8;
      }
      if(str.equals("。")){
        n++;tempPx=0;
      }else{
        if(tempPx > ziSize){
          n++;tempPx=0;
        }
      }

    }
    return n;
  }


  //是否为中文
  public boolean isChinese(String temp) {
      boolean a = false;

    Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
    Matcher m = p.matcher(temp);
    if (m.find()) {
        return true;
    }
    return false;
  }


  /**
   *  画指北标识
   *  预计宽度：1000
   */
public void sgCompass(float windowDXFWidth , float windowDXFHeight){
  //
//  int x1 = 1000, y1 = 45;
  int x1 = (int)windowDXFWidth, y1 = 45;
  int zx11=970,zy11=50 ,zx12=950,zy12=100,
      zx21=950,zy21=100,zx22=970,zy22=85 ,
      zx31=970,zy31=85 ,zx32=990,zy32=100,
      zx41=990,zy41=100,zx42=970,zy42=50;

//  int arrX[]={1030, 1010, 1030, 1050},
//          arrY[]={ -25, 15,  0, 15};

  float arrX[]={windowDXFWidth+30, windowDXFWidth+10, windowDXFWidth+30, windowDXFWidth+50},
          arrY[]={ -25, 15,  0, 15};

  Color cl = Color.black;


  if (Xprt!= null) {
    //用此作图
//    DXFLayer Layer = new DXFLayer(strLine);
//    Xprt.setCurrentLayer(Layer);
    DXFData Dt = new DXFData();
    //画直线(指北图示)
//    Dt.LayerName = Layer.getName();
//    Dt.Color = (Constants.convertColorRGBToDXF(cl));

    Dt.Count = 1;
    Dt.Style = HatchStyle.hsSolid;// default value
    Dt.Points = new ArrayList(1);
    Dt.Points.add(new ArrayList(arrX.length));
    for (int i = 0; i< arrX.length; ++i)
      ((ArrayList) Dt.Points.get(0)).add(new DXFPoint(arrX[i], -arrY[i], 0));
    Xprt.addHatch(Dt);
    Dt.Point = new DXFPoint(arrX[0], -(arrY[3]-2), 0);

    //添加文字
    Dt.Point.setTo(x1-34+60, y1+5, 0);
    Dt.FHeight = 10;
    Dt.Text = new String("N");
    Xprt.addText(Dt);


    Dt = null;
  }

}


/**
 *  整体的矩形大框
 */
public void sgDrawWholeRectangle(float x1 , float y1 , float x2 , float y2){
//  int x1=0, y1=0, x2=340, y2=240;

  Color cl = Color.black;
  DXFLayer Layer = new DXFLayer(strRectangle);
  Xprt.setCurrentLayer(Layer);
  DXFData Dt = new DXFData();
  Dt.LayerName = Layer.getName();
  Dt.Color = (Constants.convertColorRGBToDXF(cl));
  //画矩形框
  Dt.Point = new DXFPoint(x1, -y1+110, 0);
  Dt.Point1 = new DXFPoint(x2+90, -y2+350, 0);
  Xprt.addRectangle(Dt);
}

/**
 *  画左上角图例标识
 */
public void sgIdentification() throws Exception {
  int x1=0, y1=0, x2=340, y2=240;
  int byx11=20, byy21=-100, byx21=30, byy22=-100,radius=10;
  Color cl = Color.black;
//  Font f1 = new Font("宋体");
  if (grphCanvas != null) {
    grphCanvas.setColor(cl);
//    grphCanvas.setFont(f1);
    grphCanvas.drawString(strRectangle, x1+10, y1+16);
    grphCanvas.drawRect(x1, y1, x2-x1, y2-y1);
  }
  if (Xprt != null) {
    DXFLayer Layer = new DXFLayer(strRectangle);
    Xprt.setCurrentLayer(Layer);
    DXFData Dt = new DXFData();
    Dt.LayerName = Layer.getName();
    Dt.Color = (Constants.convertColorRGBToDXF(cl));
  //画矩形框
    Dt.Point = new DXFPoint(x1, -y1+110, 0);
    Dt.Point1 = new DXFPoint(x2-65, -y2+125, 0);
    Xprt.addRectangle(Dt);

    //  图例（0,30,340,595）
    Dt.Point = new DXFPoint(x1, -y1+85, 0);
    Dt.Point1 = new DXFPoint(x2-65, -y1+85, 0);
    Xprt.addLine(Dt);
    Dt.FHeight = 8;
    Dt.Point.setTo(x2-65-92*2, -y1+90, 0);
    Dt.Text = new String("图");
    Xprt.addText(Dt);
    Dt.Point.setTo(x2-65-92, -y1+90, 0);
    Dt.Text = new String("例");
    Xprt.addText(Dt);

    //变压器

    Dt.Point = new DXFPoint(byx11+radius, -(byy21+radius+35), 0);
    Dt.Radius = radius;
    Dt.SelfType = HatchBoundaryType.hbtCircle;
    Dt.StartAngle = 0;
    Dt.EndAngle = 360;
    Xprt.addHatch(Dt);
    Xprt.addCircle(Dt);

    Dt.Point = new DXFPoint(byx21+radius, -(byy22+radius+35), 0);
    Dt.Radius = radius;
    Xprt.addCircle(Dt);

    Dt.Point = new DXFPoint(byx21+30, -(byy22+radius-5+35), 0);
    Dt.FHeight = 8;
    Dt.Text = new String("变压器");
    Xprt.addMText(Dt);


    //杆塔
    Dt.Point = new DXFPoint(byx11+160, -(byy22+10+35), 0);
    Dt.Radius = radius;
    Xprt.addCircle(Dt);
//    Dt.Radius = Dt.Radius / 2;
    Dt.SelfType = HatchBoundaryType.hbtCircle;
    Dt.StartAngle = 0;
    Dt.EndAngle = 360;
    Xprt.addHatch(Dt);
    Dt.FHeight = 8;
    Dt.Point.setTo(byx11+199, -(byy22+radius+3+35), 0);
    Dt.Text = new String("杆塔");
    Xprt.addText(Dt);

    //10kv线路
    // 1横(16,13)
    Dt.Point = new DXFPoint(byx11-4, -(byy22+radius+35+35), 0);
    Dt.Point1 = new DXFPoint(byx11-7, -(byy22+radius+35+35), 0);
    Xprt.addLine(Dt);
    //   2横(22,19)
    Dt.Point = new DXFPoint(byx11+2,  -(byy22+radius+35+35), 0);
    Dt.Point1 = new DXFPoint(byx11-1,  -(byy22+radius+35+35), 0);
    Xprt.addLine(Dt);
    //    3横(28,25)
    Dt.Point = new DXFPoint(byx11+8,-(byy22+radius+35+35), 0);
    Dt.Point1 = new DXFPoint(byx11+5, -(byy22+radius+35+35), 0);
    Xprt.addLine(Dt);
    //  1列
    Dt.Point = new DXFPoint(byx11+8,  -(byy22+radius+45+35), 0);
    Dt.Point1 = new DXFPoint(byx11+8,  -(byy22+radius+25+35), 0);
    Xprt.addLine(Dt);
    //   4横 (34,31)
    Dt.Point = new DXFPoint(byx11+14, -(byy22+radius+35+35), 0);
    Dt.Point1 = new DXFPoint(byx11+11, -(byy22+radius+35+35), 0);
    Xprt.addLine(Dt);
    //  2列
    Dt.Point = new DXFPoint(byx11+14,  -(byy22+radius+45+35), 0);
    Dt.Point1 = new DXFPoint(byx11+14,  -(byy22+radius+25+35), 0);
    Xprt.addLine(Dt);
    //    5横(40,37)
    Dt.Point = new DXFPoint(byx11+20, -(byy22+radius+35+35), 0);
    Dt.Point1 = new DXFPoint(byx11+17, -(byy22+radius+35+35), 0);
    Xprt.addLine(Dt);
    //  3列
    Dt.Point = new DXFPoint(byx11+20,  -(byy22+radius+45+35), 0);
    Dt.Point1 = new DXFPoint(byx11+20,  -(byy22+radius+25+35), 0);
    Xprt.addLine(Dt);
    //    6横(46,43)
    Dt.Point = new DXFPoint(byx11+26, -(byy22+radius+35+35), 0);
    Dt.Point1 = new DXFPoint(byx11+23, -(byy22+radius+35+35), 0);
    Xprt.addLine(Dt);
    //    7横(52,47)
    Dt.Point = new DXFPoint(byx11+32, -(byy22+radius+35+35), 0);
    Dt.Point1 = new DXFPoint(byx11+29, -(byy22+radius+35+35), 0);
    Xprt.addLine(Dt);

    Dt.Point.setTo(byx11+40, -(byy22+radius+35+35), 0);
    Dt.FHeight = 8;
    Dt.Text = new String("10KV线路");
    Xprt.addText(Dt);

    //0.38kv线路
    // 1横(16,13)
//    Dt.Point = new DXFPoint(byx11+140, -(byy22+radius+35), 0);
//    Dt.Point1 = new DXFPoint(byx11+137, -(byy22+radius+35), 0);
//    Xprt.addLine(Dt);
    //   2横(22,19)
    Dt.Point = new DXFPoint(byx11+146,  -(byy22+radius+35+35), 0);
    Dt.Point1 = new DXFPoint(byx11+143,  -(byy22+radius+35+35), 0);
    Xprt.addLine(Dt);

    //    3横(28,25)
    Dt.Point = new DXFPoint(byx11+152,-(byy22+radius+35+35), 0);
    Dt.Point1 = new DXFPoint(byx11+149, -(byy22+radius+35+35), 0);
    Xprt.addLine(Dt);
    //  1列
    Dt.Point = new DXFPoint(byx11+152,  -(byy22+radius+45+35), 0);
    Dt.Point1 = new DXFPoint(byx11+152,  -(byy22+radius+25+35), 0);
    Xprt.addLine(Dt);
    //   4横 (34,31)
    Dt.Point = new DXFPoint(byx11+158, -(byy22+radius+35+35), 0);
    Dt.Point1 = new DXFPoint(byx11+155, -(byy22+radius+35+35), 0);
    Xprt.addLine(Dt);
    //  2列
    Dt.Point = new DXFPoint(byx11+158,  -(byy22+radius+45+35), 0);
    Dt.Point1 = new DXFPoint(byx11+158,  -(byy22+radius+25+35), 0);
    Xprt.addLine(Dt);
    //    5横(40,37)
    Dt.Point = new DXFPoint(byx11+164, -(byy22+radius+35+35), 0);
    Dt.Point1 = new DXFPoint(byx11+161, -(byy22+radius+35+35), 0);
    Xprt.addLine(Dt);
    //  3列
    Dt.Point = new DXFPoint(byx11+164,  -(byy22+radius+45+35), 0);
    Dt.Point1 = new DXFPoint(byx11+164,  -(byy22+radius+25+35), 0);
    Xprt.addLine(Dt);
    //    6横(46,43)
    Dt.Point = new DXFPoint(byx11+170, -(byy22+radius+35+35), 0);
    Dt.Point1 = new DXFPoint(byx11+167, -(byy22+radius+35+35), 0);
    Xprt.addLine(Dt);
    //  4列
    Dt.Point = new DXFPoint(byx11+170,  -(byy22+radius+45+35), 0);
    Dt.Point1 = new DXFPoint(byx11+170,  -(byy22+radius+25+35), 0);
    Xprt.addLine(Dt);
    //    7横(52,47)
    Dt.Point = new DXFPoint(byx11+176, -(byy22+radius+35+35), 0);
    Dt.Point1 = new DXFPoint(byx11+173, -(byy22+radius+35+35), 0);
    Xprt.addLine(Dt);

    Dt.Point.setTo(byx11+180, -(byy22+radius+35+35), 0);
    Dt.FHeight = 8;
    Dt.Text = new String("0.38KV线路");
    Xprt.addText(Dt);


    //0.22kv线路
    // 1横(16,13)
    Dt.Point = new DXFPoint(byx11-4, -(byy22+radius+75+35), 0);
    Dt.Point1 = new DXFPoint(byx11-7, -(byy22+radius+75+35), 0);
    Xprt.addLine(Dt);
    //   2横(22,19)
    Dt.Point = new DXFPoint(byx11+2,  -(byy22+radius+75+35), 0);
    Dt.Point1 = new DXFPoint(byx11-1,  -(byy22+radius+75+35), 0);
    Xprt.addLine(Dt);
    //    3横(28,25)
    Dt.Point = new DXFPoint(byx11+8,-(byy22+radius+75+35), 0);
    Dt.Point1 = new DXFPoint(byx11+5, -(byy22+radius+75+35), 0);
    Xprt.addLine(Dt);
    //  1列
//    Dt.Point = new DXFPoint(byx11+8,  -(byy22+radius+45), 0);
//    Dt.Point1 = new DXFPoint(byx11+8,  -(byy22+radius+25), 0);
//    Xprt.addLine(Dt);
    //   4横 (34,31)
    Dt.Point = new DXFPoint(byx11+14, -(byy22+radius+75+35), 0);
    Dt.Point1 = new DXFPoint(byx11+11, -(byy22+radius+75+35), 0);
    Xprt.addLine(Dt);
    //  2列
    Dt.Point = new DXFPoint(byx11+14,  -(byy22+radius+85+35), 0);
    Dt.Point1 = new DXFPoint(byx11+14,  -(byy22+radius+65+35), 0);
    Xprt.addLine(Dt);
    //    5横(40,37)
    Dt.Point = new DXFPoint(byx11+20, -(byy22+radius+75+35), 0);
    Dt.Point1 = new DXFPoint(byx11+17, -(byy22+radius+75+35), 0);
    Xprt.addLine(Dt);
    //  3列
    Dt.Point = new DXFPoint(byx11+20,  -(byy22+radius+85+35), 0);
    Dt.Point1 = new DXFPoint(byx11+20,  -(byy22+radius+65+35), 0);
    Xprt.addLine(Dt);
    //    6横(46,43)
    Dt.Point = new DXFPoint(byx11+26, -(byy22+radius+75+35), 0);
    Dt.Point1 = new DXFPoint(byx11+23, -(byy22+radius+75+35), 0);
    Xprt.addLine(Dt);
    //    7横(52,47)
    Dt.Point = new DXFPoint(byx11+32, -(byy22+radius+75+35), 0);
    Dt.Point1 = new DXFPoint(byx11+29, -(byy22+radius+75+35), 0);
    Xprt.addLine(Dt);

    Dt.Point.setTo(byx11+40, -(byy22+radius+75+35), 0);
    Dt.FHeight = 8;
    Dt.Text = new String("0.22KV线路");
    Xprt.addText(Dt);


    //跨越物
//    int arrX[]={190, 190, 210, 252 , 252 , 232 },
//        arrY[]={ 100,105, 105, 100 , 105 , 105 };

    int arrX1[]={177, 175, 175},
        arrY1[]={ -13,-13, -11},
        arrX2[]={186, 188, 188},
        arrY2[]={-13, -13, -11};

//    190,100,190,105,210,105       (177,-13)(175,-13)(175,-11)
//    252,100,252,105,232,105       (186,-13)(188,-13)(188,-11)

    //  第一根横线(155,-13) (177,-13)
    Dt.Point = new DXFPoint(byx11+135, -(byy22+radius+77+35), 0);
    Dt.Point1 = new DXFPoint(byx11+157, -(byy22+radius+77+35), 0);
    Xprt.addLine(Dt);

    Dt.Point = new DXFPoint(byx11+147, -(byy22+radius+73+35), 0);
    Dt.Point1 = new DXFPoint(byx11+147, -(byy22+radius+77+35), 0);
    Xprt.addLine(Dt);

    Dt.Point = new DXFPoint(byx11+147, -(byy22+radius+73+35), 0);
    Dt.Point1 = new DXFPoint(byx11+157, -(byy22+radius+77+35), 0);
    Xprt.addLine(Dt);

    // 第二根横线(186,-13) (208,-13)
    Dt.Point = new DXFPoint(byx11+166, -(byy22+radius+77+35), 0);
    Dt.Point1 = new DXFPoint(byx11+188, -(byy22+radius+77+35), 0);
    Xprt.addLine(Dt);

    Dt.Point = new DXFPoint(byx11+176, -(byy22+radius+73+35), 0);
    Dt.Point1 = new DXFPoint(byx11+176, -(byy22+radius+77+35), 0);
    Xprt.addLine(Dt);

    Dt.Point = new DXFPoint(byx11+176, -(byy22+radius+73+35), 0);
    Dt.Point1 = new DXFPoint(byx11+166, -(byy22+radius+77+35), 0);
    Xprt.addLine(Dt);

    Dt.Point.setTo(byx11+199, -(byy22+radius+75+35), 0);
    Dt.FHeight = 8;
    Dt.Text = new String("跨越物");
    Xprt.addText(Dt);


    //搭火点
    Dt.Point = new DXFPoint(byx11+radius+5, -(byy21+radius+115+35), 0);
    Dt.Radius = radius;
    Xprt.addCircle(Dt);
    Dt.Radius = Dt.Radius / 2;
    Dt.SelfType = HatchBoundaryType.hbtCircle;
    Dt.StartAngle = 0;
    Dt.EndAngle = 360;
    Xprt.addHatch(Dt);
    Dt.FHeight = 8;
    Dt.Point.setTo(byx21+30, -(byy22+radius+115+35), 0);
    Dt.Text = new String("搭火点");
    Xprt.addText(Dt);


    //拉线
    Dt.Point = new DXFPoint(byx11+160, -(byy22+radius+100+35), 0);
    Dt.Point1 = new DXFPoint(byx11+160, -(byy22+radius+115+35), 0);
    Xprt.addLine(Dt);

    Dt.Point = new DXFPoint(byx11+150, -(byy22+radius+115+35), 0);
    Dt.Point1 = new DXFPoint(byx11+170, -(byy22+radius+115+35), 0);
    Xprt.addLine(Dt);
    Dt.FHeight = 8;
    Dt.Point.setTo(byx11+199, -(byy22+radius+115+35), 0);
    Dt.Text = new String("拉线");
    Xprt.addText(Dt);


    //户表箱
    Dt.Point = new DXFPoint(byx11+0, -(byy21+radius+140+35), 0);
    Dt.Point1 = new DXFPoint(byx11+30, -(byy21+radius+155+35), 0);
    Xprt.addRectangle(Dt);
    Dt.FHeight = 6;
    Dt.Point.setTo(byx11+0, -(byy21+radius+150+35), 0);
    Dt.Text = new String("户表");
    Xprt.addText(Dt);
    Dt.FHeight = 8;
    Dt.Point.setTo(byx21+30, -(byy22+radius+150+35), 0);
    Dt.Text = new String("户表箱");
    Xprt.addText(Dt);


    //下户点
    Dt.Point = new DXFPoint(byx11+135, -(byy21+radius+140+35), 0);
    Dt.Point1 = new DXFPoint(byx11+198, -(byy21+radius+155+35), 0);
    Xprt.addRectangle(Dt);

    Dt.Point = new DXFPoint(byx11+175, -(byy22+radius+140+35), 0);
    Dt.Point1 = new DXFPoint(byx11+175, -(byy22+radius+155+35), 0);
    Xprt.addLine(Dt);

    Dt.FHeight = 6;
    Dt.Point.setTo(byx11+136, -(byy21+radius+150+35), 0);
    Dt.Text = new String("名称");
    Xprt.addText(Dt);

    Dt.FHeight = 6;
    Dt.Point.setTo(byx11+176, -(byy21+radius+150+35), 0);
    Dt.Text = new String("数量");
    Xprt.addText(Dt);

    Dt.FHeight = 8;
    Dt.Point.setTo(byx11+199, -(byy22+radius+150+35), 0);
    Dt.Text = new String("下户点");
    Xprt.addText(Dt);

//    Dt.Point = new DXFPoint(x1, -y1, 0);
//    Dt.Point1 = new DXFPoint(x2, -y2, 0);
//    Xprt.addLine(Dt);
//
//



    Dt = null;
  }
}




/**
 * 画右下角设计信息框
 */
public void sgDesign_info(List<DPointEntity> dPointList , float windowDXFWidth , float windowDXFHeight){

  int Design_info_width_11 = 550 , Design_info_height_21 = 200 ,Design_info_width_12 = 450 , Design_info_height_22 = 800;
//  int x1=550, y1=650, x2=1000, y2=420;
  int x1=(int)windowDXFWidth-450, y1=(int)windowDXFHeight-350, x2=(int)windowDXFWidth, y2=(int)windowDXFHeight-580;
  Color cl = Color.black;
  if (grphCanvas != null) {
    grphCanvas.setColor(cl);
    grphCanvas.drawString(strRectangle, x1+10, y1+16);
    grphCanvas.drawRect(x1, y1, x2-x1, y2-y1);
  }
  if (Xprt != null) {
    DXFLayer Layer = new DXFLayer(strRectangle);
    Xprt.setCurrentLayer(Layer);
    DXFData Dt = new DXFData();
    Dt.LayerName = Layer.getName();
    Dt.Color = (Constants.convertColorRGBToDXF(cl));
    //矩形框(550,-650,0) (1000,-420,0)
//    Dt.Point = new DXFPoint(x1+90, -y1, 0);
//    Dt.Point1 = new DXFPoint(x2+90, -y2-50, 0);
//    Xprt.addRectangle(Dt);

    Dt.Point = new DXFPoint(x1+90, -y1, 0);
    Dt.Point1 = new DXFPoint(x2+90, -y2-50-41, 0);
    Xprt.addRectangle(Dt);

    //第一行
//    Dt.Point = new DXFPoint(x1+90, -y1+139, 0);
//    Dt.Point1 = new DXFPoint(x2+90, -y1+139, 0);
//    Xprt.addLine(Dt);
    //第四列
//    Dt.Point = new DXFPoint(x1+225+90, -y1, 0);
//    Dt.Point1 = new DXFPoint(x2-225+90, -y2-50, 0);
//    Xprt.addLine(Dt);

    Dt.Point = new DXFPoint(x1+225+90, -y1, 0);
    Dt.Point1 = new DXFPoint(x2-225+90, -y2-50-41, 0);
    Xprt.addLine(Dt);

    //  xxx示意图
    String nseName = projectName+"示意图";
    int ios = nseName.length();
    String iod = "";
    String iof = "";
//    x1+225+90+10
    if(ios>12 && ios<=15){// 位置前移

      Dt.Point.setTo(x1+260+90, -y1+90, 0);
      Dt.FHeight = 8;
      Dt.Text = new String(nseName);
      Xprt.addText(Dt);
    }else if(ios > 16){//  大于14个字就换行
      iod = nseName.substring(0,14);
      Dt.Point.setTo(x1+260+90, -y1+95, 0);
      Dt.FHeight = 8;
      Dt.Text = new String(iod);
      Xprt.addText(Dt);

      iof = nseName.substring(14);
      Dt.Point.setTo(x1+260+90, -y1+80, 0);
      Dt.FHeight = 8;
      Dt.Text = new String(iof);
      Xprt.addText(Dt);
    }else {// 原来位置
      Dt.Point.setTo(x1+310+90, -y1+90, 0);
      Dt.FHeight = 8;
      Dt.Text = new String(nseName);
      Xprt.addText(Dt);
    }


    //第一列
//    Dt.Point = new DXFPoint(x1+40+90, -y1, 0);
//    Dt.Point1 = new DXFPoint(x2-410+90, -y2-50, 0);
//    Xprt.addLine(Dt);

    Dt.Point = new DXFPoint(x1+40+90, -y1, 0);
    Dt.Point1 = new DXFPoint(x2-410+90, -y2-50-41, 0);
    Xprt.addLine(Dt);

    //日期
    Dt.Point.setTo(x1+90+10, -y1+20, 0);
    Dt.FHeight = 8;
    Dt.Text = new String("日期");
    Xprt.addText(Dt);

    //第二列
//    Dt.Point = new DXFPoint(x1+110+90, -y1, 0);
//    Dt.Point1 = new DXFPoint(x2-340+90, -y2-50, 0);
//    Xprt.addLine(Dt);

    Dt.Point = new DXFPoint(x1+110+90, -y1, 0);
    Dt.Point1 = new DXFPoint(x2-340+90, -y2-50-41, 0);
    Xprt.addLine(Dt);

    //比例
    Dt.Point.setTo(x1+110+90+10, -y1+20, 0);
    Dt.FHeight = 8;
    Dt.Text = new String("比例");
    Xprt.addText(Dt);

    //第三列
//    Dt.Point = new DXFPoint(x1+150+90, -y1, 0);
//    Dt.Point1 = new DXFPoint(x2-300+90, -y2-50, 0);
//    Xprt.addLine(Dt);

    Dt.Point = new DXFPoint(x1+150+90, -y1, 0);
    Dt.Point1 = new DXFPoint(x2-300+90, -y2-50-41, 0);
    Xprt.addLine(Dt);

    //第二行
    Dt.Point = new DXFPoint(x1+90, -y1+104, 0);
    Dt.Point1 = new DXFPoint(x2-340+90, -y1+104, 0);
    Xprt.addLine(Dt);

    Dt.Point = new DXFPoint(x1+150+90, -y1+104, 0);
    Dt.Point1 = new DXFPoint(x2-225+90, -y1+104, 0);
    Xprt.addLine(Dt);

    //批准
    Dt.Point.setTo(x1+90+10, -y1+120, 0);
    Dt.FHeight = 8;
    Dt.Text = new String("批准");
    Xprt.addText(Dt);

    //第三行
    Dt.Point = new DXFPoint(x1+40+90, -y1+73, 0);
    Dt.Point1 = new DXFPoint(x2-225+90, -y1+73, 0);
    Xprt.addLine(Dt);

    //校核
    Dt.Point.setTo(x1+110+90+10, -y1+104, 0);
    Dt.FHeight = 8;
    Dt.Text = new String("校核");
    Xprt.addText(Dt);

    //第五列
    Dt.Point = new DXFPoint(x1+270+90, -y1, 0);
    Dt.Point1 = new DXFPoint(x2-180+90, -y2-190, 0);
    Xprt.addLine(Dt);
    //第六列
//    Dt.Point = new DXFPoint(x1+350+90, -y1+139, 0);
//    Dt.Point1 = new DXFPoint(x2-100+90, -y1+180, 0);
//    Xprt.addLine(Dt);

    Dt.Point = new DXFPoint(x1+350+90, -y1, 0);
    Dt.Point1 = new DXFPoint(x2-100+90, -y2-190, 0);
    Xprt.addLine(Dt);
    //第七列
    Dt.Point = new DXFPoint(x1+392+90, -y1, 0);
    Dt.Point1 = new DXFPoint(x2-58+90, -y2-190, 0);
    Xprt.addLine(Dt);

    //审核
    Dt.Point.setTo(x1+90+10, -y1+73, 0);
    Dt.FHeight = 8;
    Dt.Text = new String("审核");
    Xprt.addText(Dt);

    //设计
    Dt.Point.setTo(x1+110+90+10, -y1+56, 0);
    Dt.FHeight = 8;
    Dt.Text = new String("设计");
    Xprt.addText(Dt);

    //图号
    Dt.Point.setTo(x1+225+90+10, -y1+20, 0);
    Dt.FHeight = 8;
    Dt.Text = new String("图号");
    Xprt.addText(Dt);

    //版次
    Dt.Point.setTo(x1+350+90+10, -y1+20, 0);
    Dt.FHeight = 8;
    Dt.Text = new String("版次");
    Xprt.addText(Dt);

    //最后一行
    Dt.Point = new DXFPoint(x1+90, -y1+40, 0);
    Dt.Point1 = new DXFPoint(x2+90, -y1+40, 0);
    Xprt.addLine(Dt);
    //第一列分割线
//    Dt.Point = new DXFPoint(x1+276, -y1, 0);
//    Dt.Point1 = new DXFPoint(x2+276, -y2, 0);
//    Xprt.addLine(Dt);
//    //第二列分割线
//    Dt.Point = new DXFPoint(x1+460, -y1, 0+46);
//    Dt.Point1 = new DXFPoint(x2+460, -y2, 0+46);
//    Xprt.addRectangle(Dt);
    //第二行
//    Dt.Point3 = new DXFPoint(x1, -y1+80, 0);
//    Dt.Point4 = new DXFPoint(x2+138, -y2+80, 0);
//    Xprt.addRectangle(Dt);


    //文字
//    Dt.Point.setTo(x1+10, -(y1+16), 0);
//    Dt.FHeight = 6;
//    Dt.Text = new String(strRectangle);
//    Xprt.addText(Dt);
    Dt = null;
  }

}


  /**
   *  画直线
   * Draw a line.
   */
  public void sgDrawLine() {
    int x1=10, y1=180, x2=20, y2=40;
    Color cl = Color.blue;
    if (grphCanvas != null) {
      grphCanvas.setColor(cl);
      grphCanvas.drawString(strLine, x1, y2-20);
      grphCanvas.drawLine(x1, y1, x2, y2);
    }
    if (Xprt!= null) {
      //用此作图
      DXFLayer Layer = new DXFLayer(strLine);
      Xprt.setCurrentLayer(Layer);
      DXFData Dt = new DXFData();
      Dt.LayerName = Layer.getName();
      Dt.Color = (Constants.convertColorRGBToDXF(cl));
      Dt.Point = new DXFPoint(x1, -y1, 0);
      Dt.Point1 = new DXFPoint(x2, -y2, 0);
      Xprt.addLine(Dt);
      Dt.Point.setTo(x1, -(y2-20), 0);
      Dt.FHeight = 10;
      Dt.Text = new String(strLine);
      Xprt.addText(Dt);
      Dt = null;
    }
  }


  /**
   *  画折线
   * Draw a polyline.
   */
  public void sgDrawPolyline() {
    int arrX[]= {25,50,30,100,120}, arrY[]={90,60,130,50,110};
    Color cl = new Color(0,255,0);
    if (grphCanvas != null) {
      grphCanvas.setColor(cl);
      grphCanvas.drawString(strPolyline, 44, 56);
      grphCanvas.drawPolyline(arrX, arrY, 5);
    }
    if (Xprt != null) {
      DXFLayer Layer = new DXFLayer(strPolyline);
      Xprt.setCurrentLayer(Layer);
      DXFData Dt = new DXFData();
      Dt.LayerName = Layer.getName();
      Dt.Color = (Constants.convertColorRGBToDXF(cl));
      Dt.Count = arrX.length;
      Dt.Points = new ArrayList(Dt.Count);
      for (int i = 0; i< Dt.Count; ++i)
    	  Dt.Points.add(new DXFPoint(arrX[i], -(arrY[i]), 0));
      Xprt.addPolyline(Dt);
      Dt.Point = new DXFPoint(44, -56, 0);
      Dt.FHeight = 6;
      Dt.Text = new String(strPolyline);
      Xprt.addText(Dt);
      Dt = null;
    }
  }


  /**
   *  画矩形
   * Draw a rectangle.
   */
  public void sgDrawRectangle() {
    int x1=50, y1=120, x2=130, y2=180;
    Color cl = Color.black;
    if (grphCanvas != null) {
      grphCanvas.setColor(cl);
      grphCanvas.drawString(strRectangle, x1+10, y1+16);
      grphCanvas.drawRect(x1, y1, x2-x1, y2-y1);
    }
    if (Xprt != null) {
      DXFLayer Layer = new DXFLayer(strRectangle);
      Xprt.setCurrentLayer(Layer);
      DXFData Dt = new DXFData();
      Dt.LayerName = Layer.getName();
      Dt.Color = (Constants.convertColorRGBToDXF(cl));
      Dt.Point = new DXFPoint(x1, -y1, 0);
      Dt.Point1 = new DXFPoint(x2, -y2, 0);
      Xprt.addRectangle(Dt);
      Dt.Point.setTo(x1+10, -(y1+16), 0);
      Dt.FHeight = 6;
      Dt.Text = new String(strRectangle);
      Xprt.addText(Dt);
      Dt = null;
    }
  }


  /**
   *  画圆
   * Draw a circle.
   */
  public void sgDrawCircle() {
    int x=110, y=50, radius=15;
    Color cl = new Color(0, 0, 128);
    if (grphCanvas != null) {
      grphCanvas.setColor(cl);
      grphCanvas.drawString(strCircle, x-40, y-2);
      grphCanvas.drawOval(x, y, 2*radius, 2*radius);
      grphCanvas.fillOval(x+radius/2, y+radius/2, radius, radius);
    }
    if (Xprt != null) {
      DXFLayer Layer = new DXFLayer(strCircle);
      Xprt.setCurrentLayer(Layer);
      DXFData Dt = new DXFData();
      Dt.LayerName = Layer.getName();
      Dt.Color = (Constants.convertColorRGBToDXF(cl));
      Dt.Point = new DXFPoint(x+radius, -(y+radius), 0);
      Dt.Radius = radius;
      Xprt.addCircle(Dt);
      Dt.Radius = Dt.Radius / 2;
      Dt.SelfType = HatchBoundaryType.hbtCircle;
      Dt.StartAngle = 0;
      Dt.EndAngle = 360;
      Xprt.addHatch(Dt);
      Dt.FHeight = 4;
      Dt.Point.setTo(x, -(y-2), 0);
      Dt.Text = new String(strCircle);
      Xprt.addText(Dt);
      Dt = null;
    }
  }


  /**
   * 画椭圆
   * Draw a ellipse.
   */
  public void sgDrawEllipse() {
    int x=180, y=120, xradius=30, yradius=10;
    Color cl = Color.magenta;
    if (grphCanvas != null) {
      grphCanvas.setColor(cl);
      grphCanvas.drawString(strEllipse, x-xradius, y-yradius-2);
      grphCanvas.drawOval(x-xradius, y-yradius, 2*xradius, 2*yradius);
      grphCanvas.fillOval(x-xradius/2, y-yradius/2, xradius, yradius);
    }
    if (Xprt != null) {
      DXFLayer Layer = new DXFLayer(strEllipse);
      Xprt.setCurrentLayer(Layer);
      DXFData Dt = new DXFData();
      Dt.LayerName = Layer.getName();
      Dt.Color = (Constants.convertColorRGBToDXF(cl));
      Dt.Point = new DXFPoint(x, -y, 0);
      Dt.Point1 = new DXFPoint(xradius, 0, 0);
      Dt.Radius = ((xradius >= yradius) ? ((float)yradius/xradius) : ((float)xradius/yradius));
      Dt.StartAngle = 0;
      Dt.EndAngle = 360;
      Xprt.addEllipse(Dt);
      Dt.Point1 = new DXFPoint(xradius/2, 0, 0);
      Dt.Radius = Dt.Radius / 2;
      Dt.SelfType = HatchBoundaryType.hbtEllipse;
      Xprt.addHatch(Dt);
      Dt.FHeight = 4;
      Dt.Point.setTo(x-xradius, -(y-yradius-2), 0);
      Dt.Text = new String(strEllipse);
      Xprt.addText(Dt);
      Dt = null;
    }
  }


  /**
   *  画圆弧
   * Draw a arc.
   */
  public void sgDrawArc() {
    int x=180, y=180, radius=30;
    int stAng=30, arAng=260;
    Color cl = Color.gray;
    if (grphCanvas != null) {
      grphCanvas.setColor(cl);
      grphCanvas.drawString(strArc, x-3, y);
      grphCanvas.drawArc(x-radius, y-radius, 2*radius, 2*radius, stAng, arAng);
    }
    if (Xprt != null) {
      DXFLayer Layer = new DXFLayer(strArc);
      Xprt.setCurrentLayer(Layer);
      DXFData Dt = new DXFData();
      Dt.LayerName = Layer.getName();
      Dt.Color = (Constants.convertColorRGBToDXF(cl));
      Dt.Point = new DXFPoint(x, -y, 0);
      Dt.StartAngle = stAng;
      Dt.EndAngle = arAng+stAng;
      Dt.Radius = radius;
      Xprt.addArc(Dt);
      Dt.FHeight = 12;
      Dt.Point.setTo(x-3, -y, 0);
      Dt.Text = new String(strArc);
      Xprt.addText(Dt);
      Dt = null;
    }
  }


  /**
   *  画多边形
   * Draw a hatch.
   */
  public void sgDrawPolygon() {
    Color cl = Color.cyan;
    int arrX[]= {160, 168, 150, 172, 180, 188, 210, 192, 200, 180},
        arrY[]= { 95,  76,  65,  65,  45,  65,  65,  76,  95,  83};
    if (grphCanvas != null) {
      grphCanvas.setColor(cl);
      grphCanvas.drawString(strPolygon, arrX[0], arrY[4]-2);
      grphCanvas.fillPolygon(arrX, arrY, arrX.length);
    }
    if (Xprt != null) {
      DXFLayer Layer = new DXFLayer(strPolygon);
      Xprt.setCurrentLayer(Layer);
      DXFData Dt = new DXFData();
      Dt.LayerName = Layer.getName();
      Dt.Color = (Constants.convertColorRGBToDXF(cl));
      Dt.Count = 1;
      Dt.Style = HatchStyle.hsSolid;// default value
      Dt.Points = new ArrayList(1);
      Dt.Points.add(new ArrayList(arrX.length));
      for (int i = 0; i< arrX.length; ++i)
        ((ArrayList) Dt.Points.get(0)).add(new DXFPoint(arrX[i], -arrY[i], 0));
      Xprt.addHatch(Dt);
      Dt.Point = new DXFPoint(arrX[0], -(arrY[4]-2), 0);
      Dt.FHeight = 12;
      Dt.Text = new String(strPolygon);
      Xprt.addText(Dt);
      Dt = null;
    }
  }


  /**
   *  画贝塞尔曲线
   * Draw a Bezier.
   */
  public void sgDrawBezier() {
    int arrX[]= {70, 60,150,180,210,260,225,200,175,285,310,350,300},
        arrY[]= {80,160,180,160,140,120, 75, 90,105,105, 90, 70, 50},
        x= 240, y= 90;
    Color cl = new Color(149,122,165);
    if (grphCanvas != null) {
      grphCanvas.setColor(cl);
      grphCanvas.drawString(strBezier + " (here, only in DXF!!!)", x, y);
    }
    if (Xprt != null) {
      DXFLayer Layer = new DXFLayer(strBezier);
      Xprt.setCurrentLayer(Layer);
      DXFData Dt = new DXFData();
      Dt.LayerName = Layer.getName();
      Dt.Color = (Constants.convertColorRGBToDXF(cl));
      Dt.Count = arrX.length;
      Dt.Points = new ArrayList(Dt.Count);
      for (int i = 0; i< Dt.Count; ++i)
        Dt.Points.add(new DXFPoint(arrX[i], -arrY[i], 0));
      Xprt.addBezier(Dt);
      Dt.Point = new DXFPoint(x, -y, 0);
      Dt.FHeight = 12;
      Dt.Text = new String(strBezier);
      Xprt.addText(Dt);
      Dt = null;
    }
  }


  /**
   *  画3面
   * Draw a 3DFace.
   */
  public void sgDraw3DFace() {
    Color cl = Color.orange;
    int arrX[]= {230, 220, 250, 280, 270},
        arrY[]= {195, 165, 145, 165, 195};
    if (grphCanvas != null) {
      grphCanvas.setColor(cl);
      grphCanvas.drawString(str3DFace, arrX[0], arrY[4]-2);
      grphCanvas.drawLine(arrX[0], arrY[0], arrX[1], arrY[1]);
      grphCanvas.drawLine(arrX[1], arrY[1], arrX[2], arrY[2]);
      grphCanvas.drawLine(arrX[2], arrY[2], arrX[3], arrY[3]);
      grphCanvas.drawLine(arrX[3], arrY[3], arrX[0], arrY[0]);
      grphCanvas.drawLine(arrX[3], arrY[3], arrX[4], arrY[4]);
      grphCanvas.drawLine(arrX[4], arrY[4], arrX[0], arrY[0]);
    }
    if (Xprt != null) {
      DXFLayer Layer = new DXFLayer(str3DFace);
      Xprt.setCurrentLayer(Layer);
      DXFData Dt = new DXFData();
      Dt.LayerName = Layer.getName();
      Dt.Color = 31;
      // First 3DFace
      Dt.Point = new DXFPoint(arrX[0], -arrY[0], 0);
      Dt.Point1 = new DXFPoint(arrX[1], -arrY[1], 0);
      Dt.Point2 = new DXFPoint(arrX[2], -arrY[2], 0);
      Dt.Point3 = new DXFPoint(arrX[3], -arrY[3], 0);
      Xprt.add3DFace(Dt);
      // Second 3DFace
      Dt.Point = new DXFPoint(arrX[0], -arrY[0], 0);
      Dt.Point1 = new DXFPoint(arrX[3], -arrY[3], 0);
      Dt.Point2 = new DXFPoint(arrX[4], -arrY[4], 0);
      Dt.Point3 = new DXFPoint(arrX[0], -arrY[0], 0);
      Xprt.add3DFace(Dt);
      Dt.Point = new DXFPoint(arrX[0], -(arrY[4]-2), 0);
      Dt.FHeight = 12;
      Dt.Text = new String(str3DFace);
      Xprt.addText(Dt);
      Dt = null;
    }
  }



  //中文转换成GBK码(16进制字符串)，每个汉字2个字节
  public String Chinese2GBK(String chineseStr)throws Exception {
    StringBuffer GBKStr = new StringBuffer();
    byte[] GBKDecode = chineseStr.getBytes("gbk");
    for (byte b : GBKDecode)
      GBKStr.append(Integer.toHexString(b&0xFF));
    return GBKStr.toString().toUpperCase();
  }


}
